data.cache.write_through ≡
template < typename Key, typename Value, typename LUtime, auto Associativity, auto Depth > class cache §source
A cache that immediately writes data to the backing store.
Parameters
-
typename KeyThe type of key for looking up a value in the cache.
-
typename ValueThe type of value stored in the cache.
-
typename LUtimeThe type to use for storing the time a cache entry was most recently used. Using a wider type makes LRU eviction more accurate for a set associative cache, but for a direct cache where LRU does not apply, using uint1 saves space.
-
auto AssociativityThe number of entries to store for a given hash value. Use 1 to create a directly mapped cache.
-
auto DepthThe total number of entries to cache. Must be a multiple of
Associativity.
Callbacks and Fields
Methods
-
inline Value store_value_in_cache( cache::set_index_t set_index, cache::entry_index_t entry_index, Value newValue, bool readFromCache ) §source
Stores a value in the cache, or reads the existing value if
readFromCacheis true. Called by bothgetandput, and serves as a single place with a single atomic block for manipulating the contents of the cached data. Returns the value now in the cache, which may have just been written there.Arguments
-
cache::set_index_t set_index
The hashed value of the key.
-
cache::entry_index_t entry_index
The index within the cache line for the given entry.
-
Value newValueThe value to store into the cache.
-
bool readFromCache
Set to true if this function should return the existing value from the cache.
-
-
Value get_or_put( bool is_get, Key key, cache::set_index_t set_index, Value value ) §source
Gets or puts a value from/to the cache.
Arguments
-
bool is_get
Whether this is a get operation. If false, this is a put operation.
-
Key keyThe key to read or write.
-
cache::set_index_t set_index
The hashed value of the key.
-
Value valueThe new value to put. Ignored if
is_getis true.
-
-
void initialize() §source
Initialize or re-initialize a cache object. Re-initializing the cache invalidates all entries. The caller must ensure that intialize is not called concurrently with get or put.
-
Value get(Key key, cache::set_index_t set_index) §source
Gets a value from the cache.
Arguments
-
Key keyThe key to lookup.
-
cache::set_index_t set_index
The hashed value of the key.
-
-
void put(Key key, cache::set_index_t set_index, Value value) §source
Puts a value into the cache.
Arguments
-
Key keyThe key to write.
-
cache::set_index_t set_index
The hashed value of the key.
-
Value valueThe new value to put.
-