ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
CircuitCache Class Reference

Bounded LRU cache mapping gate UUIDs to their CircuitCacheInfos. More...

#include "CircuitCache.h"

Public Types

typedef CircuitCacheInfos item_type
 The value type stored in the cache.
 
typedef item_list::iterator iterator
 Iterator type for iterating over cache entries in FIFO order.
 

Public Member Functions

 CircuitCache ()
 Construct an empty cache.
 
bool insert (const CircuitCacheInfos &infos)
 Insert a new gate into the cache, evicting the oldest if necessary.
 
std::optional< CircuitCacheInfosget (pg_uuid_t token) const
 Look up a gate by UUID.
 
iterator begin ()
 Iterator to the first cached entry (oldest).
 
iterator end ()
 Past-the-end iterator for the cache.
 

Private Types

typedef multi_index_container< CircuitCacheInfos, indexed_by< sequenced<>, hashed_unique< member< CircuitCacheInfos, pg_uuid_t, &CircuitCacheInfos::token > > > > item_list
 Boost multi-index container type for cache entries.
 

Private Attributes

item_list il
 The container holding cached entries.
 
unsigned current_size
 Current total byte usage of cached entries.
 

Detailed Description

Bounded LRU cache mapping gate UUIDs to their CircuitCacheInfos.

Internally a Boost multi_index_container provides two views of the same data:

  • A sequenced (insertion-order) index used to evict the oldest entry when the cache is full.
  • A hashed-unique index keyed on token for O(1) lookup.

The cache is not thread-safe; each backend process maintains its own instance.

Definition at line 71 of file CircuitCache.h.

Member Typedef Documentation

◆ item_list

typedef multi_index_container< CircuitCacheInfos, indexed_by< sequenced<>, hashed_unique<member<CircuitCacheInfos, pg_uuid_t, &CircuitCacheInfos::token> > > > CircuitCache::item_list
private

Boost multi-index container type for cache entries.

Definition at line 80 of file CircuitCache.h.

◆ item_type

The value type stored in the cache.

Definition at line 86 of file CircuitCache.h.

◆ iterator

typedef item_list::iterator CircuitCache::iterator

Iterator type for iterating over cache entries in FIFO order.

Definition at line 88 of file CircuitCache.h.

Constructor & Destructor Documentation

◆ CircuitCache()

CircuitCache::CircuitCache ( )
inline

Construct an empty cache.

Definition at line 91 of file CircuitCache.h.

Member Function Documentation

◆ begin()

iterator CircuitCache::begin ( )
inline

Iterator to the first cached entry (oldest).

Returns
Iterator pointing to the oldest cache entry.

Definition at line 121 of file CircuitCache.h.

◆ end()

iterator CircuitCache::end ( )
inline

Past-the-end iterator for the cache.

Returns
Iterator one past the last cache entry.

Definition at line 128 of file CircuitCache.h.

◆ get()

std::optional< CircuitCacheInfos > CircuitCache::get ( pg_uuid_t  token) const

Look up a gate by UUID.

Parameters
tokenUUID of the gate to find.
Returns
An std::optional containing the CircuitCacheInfos if found, or std::nullopt on a cache miss.

Definition at line 43 of file CircuitCache.cpp.

Here is the caller graph for this function:

◆ insert()

bool CircuitCache::insert ( const CircuitCacheInfos infos)

Insert a new gate into the cache, evicting the oldest if necessary.

If infos.token is already present in the cache the insert is a no-op and the function returns false. Otherwise the entry is added and, if the cache exceeds its size budget, the oldest entry is removed.

Parameters
infosGate information to cache.
Returns
true if the entry was newly inserted, false if it was already present.

Definition at line 26 of file CircuitCache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ current_size

unsigned CircuitCache::current_size
private

Current total byte usage of cached entries.

Definition at line 82 of file CircuitCache.h.

◆ il

item_list CircuitCache::il
private

The container holding cached entries.

Definition at line 81 of file CircuitCache.h.


The documentation for this class was generated from the following files: