LRUCache: Class that implements LRU cache with expiring items.

LRUCacheR Documentation

Class that implements LRU cache with expiring items.

Description

LRU caches remove items in a FIFO manner, such that the oldest items to be used are the first to be removed. If you attempt to retrieve a cache item that is older than the expiration time, the item will be invalidated.

Public fields

Element

Class describes the values in the cache

Methods

Public methods


Method new()

Initialize an “LRUCache“ instance.

Usage
LRUCache$new(max_cache_items, expiration_horizon, retrieval_function)
Arguments
max_cache_items

(int): Maximum number of items to store in cache.

expiration_horizon

(datetime.timedelta): Maximum time duration a cache element can persist before being invalidated.

retrieval_function

(Callable[[KeyType, ValType], ValType]): Function which maps cache keys and current values to new values. This function must have kwarg arguments “key“ and “value“. This function is called as a fallback when the key is not found in the cache, or a key has expired.


Method clear()

Deletes all elements from the cache.

Usage
LRUCache$clear()

Method get()

Returns value corresponding to key in cache.

Usage
LRUCache$get(key, data_source_fallback = TRUE)
Arguments
key

(KeyType): Key in cache to retrieve.

data_source_fallback

(Optional[bool]): True if data should be retrieved if it's stale or not in cache. Default: True.


Method put()

Adds key to cache using “retrieval_function“. If value is provided, this is used instead. If the key is already in cache, the old element is removed. If the cache size exceeds the size limit, old elements are removed in order to meet the limit.

Usage
LRUCache$put(key, value = NULL)
Arguments
key

(KeyType): Key in cache to retrieve.

value

(Optional[ValType]): Value to store for key. Default: None.


Method clone()

The objects of this class are cloneable with this method.

Usage
LRUCache$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


DyfanJones/sagemaker-r-local documentation built on June 14, 2022, 10:32 p.m.