Skip to content
File

Blob: src/workerd/jsg/compile-cache.c++

950 bytes
1// Copyright (c) 2017-2022 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4#include "compile-cache.h"
5 
6namespace workerd::jsg {
7 
8// CompileCache::Data
9 
10std::unique_ptr<v8::ScriptCompiler::CachedData> CompileCache::Data::AsCachedData() {
11 return std::make_unique<v8::ScriptCompiler::CachedData>(
12 data, length, v8::ScriptCompiler::CachedData::BufferNotOwned);
13}
14 
15// CompileCache
16 
17void CompileCache::add(
18 kj::StringPtr key, std::shared_ptr<v8::ScriptCompiler::CachedData> cached) const {
19 cache.lockExclusive()->upsert(kj::str(key), Data(kj::mv(cached)), [](auto&, auto&&) {});
20}
21 
22kj::Maybe<CompileCache::Data&> CompileCache::find(kj::StringPtr key) const {
23 auto lock = cache.lockExclusive();
24 KJ_IF_SOME(value, lock->find(key)) {
25 if (value.data != nullptr) {
26 return value;
27 }
28 }
29 return kj::none;
30}
31 
32} // namespace workerd::jsg