CCF
Loading...
Searching...
No Matches
interpreter_cache_interface.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/endpoint.h"
6#include "ccf/js/tx_access.h"
8
9namespace ccf::js
10{
11 namespace core
12 {
13 class Context;
14 };
15
18
20 std::function<std::shared_ptr<js::core::Context>(js::TxAccess)>;
21
23 {
24 public:
25 virtual ~AbstractInterpreterCache() = default;
26
27 static char const* get_subsystem_name()
28 {
29 return "InterpreterCache";
30 }
31
32 // Retrieve an interpreter, based on reuse policy specified in the endpoint.
33 // Note that in some cases, notably if the reuse policy does not permit
34 // reuse, this will actually return a freshly-constructed, non-cached
35 // interpreter. The caller should not care whether the returned value is
36 // fresh or previously used, and should treat it identically going forward.
37 // The only benefit of a reused value from the cache should be seen during
38 // execution, where some global initialisation may already be done.
39 virtual std::shared_ptr<js::core::Context> get_interpreter(
40 js::TxAccess access,
41 const std::optional<ccf::endpoints::InterpreterReusePolicy>&
42 interpreter_reuse,
43 size_t freshness_marker) = 0;
44
45 // Cap the total number of interpreters which will be retained. The
46 // underlying cache functions as an LRU, evicting the interpreter which has
47 // been idle the longest when the cap is reached.
48 virtual void set_max_cached_interpreters(size_t max) = 0;
49
50 virtual void set_interpreter_factory(const InterpreterFactory& ip) = 0;
51 };
52}
Definition node_subsystem_interface.h:8
Definition interpreter_cache_interface.h:23
virtual void set_max_cached_interpreters(size_t max)=0
virtual std::shared_ptr< js::core::Context > get_interpreter(js::TxAccess access, const std::optional< ccf::endpoints::InterpreterReusePolicy > &interpreter_reuse, size_t freshness_marker)=0
static char const * get_subsystem_name()
Definition interpreter_cache_interface.h:27
virtual void set_interpreter_factory(const InterpreterFactory &ip)=0
virtual ~AbstractInterpreterCache()=default
Definition bundle.h:12
std::function< std::shared_ptr< js::core::Context >(js::TxAccess)> InterpreterFactory
Definition interpreter_cache_interface.h:20
TxAccess
Definition tx_access.h:10
Definition endpoint.h:198
Definition interpreter_cache_interface.h:17