proxystore.store.cache¶
Cache of values which are filled in once.
Warning
This module is an internal implementation detail which may change between releases without notice (see Versioning and Compatibility).
DEFAULT_CACHE_SIZE_BYTES
module-attribute
¶
Default maximum size of a cache in bytes (256 MiB).
LRUCache
¶
LRUCache(max_bytes: int = DEFAULT_CACHE_SIZE_BYTES)
Bases: Generic[KeyT, ValueT]
Thread-safe LRU cache of values which are filled in once.
The value of a key is filled in by one thread. The first thread to
call start() for a key fills
in the value and then calls
finish() or
fail(). Other threads which
call start() for the key in
the meantime get the same future to wait on.
The size of each value is given to
finish(), and the least
recently used values are removed while the total size is more than
max_bytes.
Parameters:
-
max_bytes(int, default:DEFAULT_CACHE_SIZE_BYTES) –Maximum total size of the cached values in bytes. A value larger than this is not cached. If 0, values are not cached once finished, but threads still share a value while it is being filled in.
Raises:
-
ValueError–If
max_bytes < 0.
Source code in proxystore/store/cache.py
evict
¶
Remove the value of a key.
A value being filled in is also removed, so it is not cached when finished. Threads waiting on it still get the value.
Source code in proxystore/store/cache.py
get
¶
Get the cached value of a key.
Returns:
-
ValueT | None–The value or
defaultif the value is not cached or is still being filled in.
Source code in proxystore/store/cache.py
start
¶
Get the value of a key or start filling it in.
If this thread is already filling in the value of the key (e.g., the code filling in the value calls this again), a new future is returned for this thread to fill in so it does not wait on itself. That value is not cached.
Returns:
Source code in proxystore/store/cache.py
finish
¶
finish(
key: KeyT,
future: Future[ValueT],
value: ValueT,
*,
size: int,
cache: bool = True,
) -> None
Finish filling in a value.
Threads waiting on the value get it. The value is cached if cache
is True, size is at most max_bytes, and the value was not
evicted while it was being
filled in.
Parameters:
-
key(KeyT) –Key of the value.
-
future(Future[ValueT]) –Future returned by
start(). -
value(ValueT) –Value of the key.
-
size(int) –Size of the value in bytes.
-
cache(bool, default:True) –Cache the value.
Source code in proxystore/store/cache.py
fail
¶
fail(
key: KeyT,
future: Future[ValueT],
exception: BaseException,
) -> None
Fail filling in a value.
Threads waiting on the value get the exception, and the next
start() fills in the
value again.