fleche.caches
Attributes
Exceptions
Cache refused to cache the call for some reason or other. |
Classes
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
A cache that can only be read from. |
|
A read-only view of a cache that only exposes calls matching a predicate. |
|
A cache that forces re-execution by always missing on load. |
|
Represents a combination of caches. |
Module Contents
- exception fleche.caches.Rejected[source]
Bases:
ExceptionCache refused to cache the call for some reason or other.
- class fleche.caches.BaseCache[source]
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstractmethod save(call: fleche.call.Call) str[source]
- load(key: str, lazy: bool = False) fleche.call.Call[source]
- load(key: str, lazy: bool = True) fleche.call.LazyCall
- abstractmethod evict(key: str | fleche.digest.Digest) None[source]
- transfer(other: BaseCache, pop: bool = False) None[source]
Transfer all calls from this cache to another cache.
Existing calls in the target cache may be overwritten by the transferred calls.
- Parameters:
other – The destination cache.
pop – If True, evict transferred keys from the source cache after moving.
- push(cache: BaseCache) CacheStack[source]
- abstractmethod shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambigious reference to the same call.
Warning
This is a property of how many values there are in your storage! A key returned from this function may become ambigious in the future when more values are added. Do not rely on this function in your programs, it is provided as a convenience for users only!
- Parameters:
key (str or
Digest) – the key to shorten- Returns:
shortest key possible
- Return type:
Digest- Raises:
AmbiguousDigestError – if no shorter key is possible
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
- table() pandas.DataFrame[source]
Return a pandas DataFrame summarizing cached calls via query().
This implementation uses a fully-wildcard Call template to retrieve all calls through
self.queryand then flattens metadata keys into top-level columns for convenience.Arguments and results are elided.
The DataFrame index will be the lookup key (digest) of each call.
- Returns:
table of all calls on cache
- Return type:
pandas.DataFrame
- filter(predicate: Callable[[fleche.call.Call | fleche.call.LazyCall], bool] | fleche.call.Call) FilteredCache[source]
Create a read-only view of this cache that only exposes calls matching the predicate.
- Parameters:
predicate – A function that takes a Call or LazyCall and returns True if it should be included in the new cache, or a Call object to use as a template.
- Returns:
A read-only view of the cache.
- Return type:
- class fleche.caches.Cache[source]
Bases:
BaseCacheHelper class that provides a standard way to create an ABC using inheritance.
- values: fleche.storage.Storage[source]
- _calls: dataclasses.InitVar[fleche.storage.CallStorage | fleche.storage.Storage][source]
- save(call: fleche.call.Call) str[source]
- _decode_call(call: fleche.call.Call, lazy: bool = False) fleche.call.Call[source]
- _decode_call(call: fleche.call.Call, lazy: bool = True) fleche.call.LazyCall
- load(key: str, lazy: bool = False) fleche.call.Call[source]
- load(key: str, lazy: bool = True) fleche.call.LazyCall
- shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambigious reference to the same call.
Warning
This is a property of how many values there are in your storage! A key returned from this function may become ambigious in the future when more values are added. Do not rely on this function in your programs, it is provided as a convenience for users only!
- Parameters:
key (str or
Digest) – the key to shorten- Returns:
shortest key possible
- Return type:
Digest- Raises:
AmbiguousDigestError – if no shorter key is possible
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
Query for cached calls that match a template and return decoded results.
This delegates to the underlying
CallStorage.query()using the provided templatecall. Any digested argument values and the result are decoded via this cache’s value storage before yielding.- Parameters:
call – A
Callinstance used as a template; fields set toNoneact as wildcards. For arguments and result, comparisons follow digest semantics (i.e., values are matched by their digest).lazy – If True, return LazyCall instances instead of Call instances.
- Yields:
Call | LazyCall – Matching calls with arguments and result decoded from digests where possible.
- evict(key: str | fleche.digest.Digest) None[source]
- class fleche.caches.ReadOnlyCache[source]
Bases:
BaseCacheA cache that can only be read from.
- save(call: fleche.call.Call)[source]
- shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambigious reference to the same call.
Warning
This is a property of how many values there are in your storage! A key returned from this function may become ambigious in the future when more values are added. Do not rely on this function in your programs, it is provided as a convenience for users only!
- Parameters:
key (str or
Digest) – the key to shorten- Returns:
shortest key possible
- Return type:
Digest- Raises:
AmbiguousDigestError – if no shorter key is possible
- evict(key: str | fleche.digest.Digest) None[source]
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
Forward queries to the wrapped cache.
- Parameters:
call – A template
CallwhereNonefields act as wildcards.lazy – If True, return LazyCall instances.
- Yields:
Call | LazyCall – Results yielded by the wrapped cache’s
querymethod.
- class fleche.caches.FilteredCache[source]
Bases:
ReadOnlyCacheA read-only view of a cache that only exposes calls matching a predicate.
- predicate: Callable[[fleche.call.Call | fleche.call.LazyCall], bool][source]
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
Forward queries to the wrapped cache.
- Parameters:
call – A template
CallwhereNonefields act as wildcards.lazy – If True, return LazyCall instances.
- Yields:
Call | LazyCall – Results yielded by the wrapped cache’s
querymethod.
- class fleche.caches.RefreshingCache[source]
Bases:
BaseCacheA cache that forces re-execution by always missing on load.
It forwards saves and value loads to an underlying cache, allowing new results to be stored while ensuring that existing ones are ignored for the duration of its use.
This is necessary to handle nested fleche calls during a rerun, otherwise forcing them to re-execute would be awkward.
- save(call: fleche.call.Call) str[source]
- load(key: str, lazy: bool = False) fleche.call.Call[source]
- load(key: str, lazy: bool = True) fleche.call.LazyCall
- evict(key: str | fleche.digest.Digest) None[source]
- shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambigious reference to the same call.
Warning
This is a property of how many values there are in your storage! A key returned from this function may become ambigious in the future when more values are added. Do not rely on this function in your programs, it is provided as a convenience for users only!
- Parameters:
key (str or
Digest) – the key to shorten- Returns:
shortest key possible
- Return type:
Digest- Raises:
AmbiguousDigestError – if no shorter key is possible
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
- class fleche.caches.CacheStack[source]
Bases:
BaseCacheRepresents a combination of caches.
Saving will always hit the lowest level, while loading will traverse up.
- save(call: fleche.call.Call)[source]
- push(cache: BaseCache) CacheStack[source]
- evict(key: str | fleche.digest.Digest) None[source]
- shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambigious reference to the same call.
Warning
This is a property of how many values there are in your storage! A key returned from this function may become ambigious in the future when more values are added. Do not rely on this function in your programs, it is provided as a convenience for users only!
- Parameters:
key (str or
Digest) – the key to shorten- Returns:
shortest key possible
- Return type:
Digest- Raises:
AmbiguousDigestError – if no shorter key is possible
- query(call: fleche.call.Call, lazy: bool = False) Iterable[fleche.call.Call][source]
- query(call: fleche.call.Call, lazy: bool = True) Iterable[fleche.call.LazyCall]
Aggregate query results across the stack, avoiding duplicates.
The caches are queried from bottom to top. Results are deduplicated by their lookup key (via
Call.to_lookup_key()) and yielded in the order they are first seen.- Parameters:
call – A template
CallwhereNonefields act as wildcards.lazy – If True, return LazyCall instances.
- Yields:
Call | LazyCall – Matching calls from any cache in the stack, without duplicates.