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 Key
    

    The type of key for looking up a value in the cache.

  • typename Value
    

    The type of value stored in the cache.

  • typename LUtime
    

    The 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 Associativity
    

    The number of entries to store for a given hash value. Use 1 to create a directly mapped cache.

  • auto Depth
    

    The total number of entries to cache. Must be a multiple of Associativity.

Aliases

Callbacks and Fields

  • (Key key) -> Value load §source
    

    The callback function to invoke when a get call causes a cache miss.

  • (Key key, Value value) -> void store §source
    

    The callback function to invoke in a put call to store the new value to the backend store.

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 readFromCache is true. Called by both get and put, 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 newValue
      

      The 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 key
      

      The key to read or write.

    • cache::set_index_t set_index
      

      The hashed value of the key.

    • Value value
      

      The new value to put. Ignored if is_get is 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 key
      

      The 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 key
      

      The key to write.

    • cache::set_index_t set_index
      

      The hashed value of the key.

    • Value value
      

      The new value to put.