Skip to content
class

ExecutableCache

ExecutableCache

Bounded-LRU cache of compiled MPSGraph executables.

Thread-safe. Entries are shared: eviction drops the cache's reference only. It used to hand out borrowed raw pointers and delete the executable on eviction, so a module holding one — every CompiledModule keeps its executables — called freed memory once more than max_entries signatures had been compiled in the process.

Constructors

1
ctor

ExecutableCache

Construct an empty cache with the default LRU cap (32 entries). Use set_max_entries to override before inserting.

Destructor

1
dtor

~ExecutableCache

Destructor — releases every cached CompiledExecutable via destroy_executable before the map is torn down.

Static methods

1
static

session

ExecutableCache & session()

Process-global session cache. First call honours the LUCID_COMPILE_MAX_CACHE environment variable (positive integer). Subsequent calls return the same instance.

Operators

1
op

operator=

ExecutableCache & operator=(const ExecutableCache &)

Methods

5
fn

clear

void clear()

Drop the cache's reference to every stored executable.

fn

find

int find(const CacheKey & key)

Look up an executable.

Returns a shared reference on hit (and bumps the entry to most-recent in the LRU order) or an empty pointer on miss.

fn

insert

int insert(CacheKey key, int exec)

Insert exec under key and return it. Replaces any existing entry (dropping the cache's reference to the previous executable). If the resulting size exceeds max_entries, drops the least-recently used entries until back at capacity.

fn

set_max_entries

void set_max_entries(int n)

Override the LRU cap. Honoured by subsequent inserts; existing entries are not evicted retroactively. Default is 32.

fnconst

size

int size()

Number of currently-cached entries.