uvm_lru_cache(KEY_T,DATA_T)

Implements a least recently used (LRU) cache.

Summary
uvm_lru_cache(KEY_T,DATA_T)
Implements a least recently used (LRU) cache.
Methods
newConstructor, initializes the cache.
sizeReturns the current number of elements in the cache.
existsReturns true if key exists in the cache, otherwise returns false.
getReturns data associated with key.
putPuts data in cache at index key.
evictRemoves the data at key from the cache.
evict_to_maxImplementation of uvm_cache#(KEY_T,DATA_T)::evict_to_max hook.
keysReturns a queue of all keys currently in the cache.

new

function new(
    string  name  =  "unnamed-uvm_lru_cache",
    size_t  max_size  =  256
)

Constructor, initializes the cache.

The max_size argument defines the initial maximum size of the cache.  The default max_size shall be 256.

A max_size of 0 indicates that the cache is unsized, and will not evict any keys.

size

virtual function size_t size()

Returns the current number of elements in the cache.

exists

virtual function bit exists(
    KEY_T  key
)

Returns true if key exists in the cache, otherwise returns false.

get

virtual function optional_data get(
    KEY_T  key
)

Returns data associated with key.

If key exists within the cache, then the data is returned via <optional_data>.

If key does not existing within the cache, then this operation shall have no effect on the cache, and shall return empty <optional_data>.

put

virtual function void put(
    KEY_T  key,
    DATA_T  data
)

Puts data in cache at index key.

If key exists within the cache, then the data associated data is updated.  If key does not exists within the cache, then a new data value is added at key.

If putting the key in the cache causes the number of stored keys to exceed <get_max_size>, then the least recently used key shall be evicted via evict.

evict

virtual function optional_data evict(
    KEY_T  key
)

Removes the data at key from the cache.

If key exists within the cache, then the data is returned via <optional_data>.

If key does not exist within the cache, then this operation shall have no effect on the cache, and shall return empty optional data.

evict_to_max

protected virtual function void evict_to_max()

Implementation of uvm_cache#(KEY_T,DATA_T)::evict_to_max hook.

Evicts least recently used keys until size is less than or equal to max size.

keys

virtual function optional_keys keys()

Returns a queue of all keys currently in the cache.

function new(
    string  name  =  "unnamed-uvm_lru_cache",
    size_t  max_size  =  256
)
Constructor, initializes the cache.
virtual function size_t size()
Returns the current number of elements in the cache.
virtual function bit exists(
    KEY_T  key
)
Returns true if key exists in the cache, otherwise returns false.
virtual function optional_data get(
    KEY_T  key
)
Returns data associated with key.
virtual function void put(
    KEY_T  key,
    DATA_T  data
)
Puts data in cache at index key.
virtual function optional_data evict(
    KEY_T  key
)
Removes the data at key from the cache.
protected virtual function void evict_to_max()
Implementation of uvm_cache#(KEY_T,DATA_T)::evict_to_max hook.
virtual function optional_keys keys()
Returns a queue of all keys currently in the cache.