Skip to main content

lru

Node

from dara.core.internal.cache_store.lru import Node

class Node()

A node in a doubly linked list.

Methods

__init__

def __init__(key: str, value: Any, pin: bool = False)

Initialize a new node.

Arguments:

  • key: The key associated with this node.
  • value: The value associated with this node.
  • pin: If true, the node will not be evicted until read.

LRUCache

from dara.core.internal.cache_store.lru import LRUCache

class LRUCache(CacheStoreImpl[LruCachePolicy])

A Least Recently Used (LRU) Cache. Evicts the least recently used items first.

Methods

delete

async def delete(key: str) -> Any

Delete an entry from the cache.

Arguments:

  • key: The key of the entry to delete.

get

async def get(key: str, unpin: bool = False) -> Optional[Any]

Retrieve a value from the cache.

Arguments:

  • key: The key of the value to retrieve.
  • unpin: If true, the entry will be unpinned if it is pinned.

Returns:

The value associated with the key, or None if the key is not in the cache.

set

async def set(key: str, value: Any, pin: bool = False) -> None

Add a key-value pair to the cache, or update the value of an existing key.

If the cache is full, evict the least recently used item.

Arguments:

  • key: The key to set.
  • value: The value to associate with the key.
  • pin: If true, the entry will not be evicted until read.

clear

async def clear()

Empty the store.