data.core.caching
Classes
Class controlling the cache. |
Module Contents
- class data.core.caching.Cache
Class controlling the cache.
See Caching for details.
- check_size(*args, **kwargs)
Check the cache size and trim it down when needed.
Automatically runs when a new entry is added to the cache or the Cache config parameters change. Does not work when the
cache-policyis “off”.The algorithm includes three steps:
first, the cache size is determined
next, if the size is larger than the limit defined by the
maximum-cache-sizeconfig the oldest cache entries are removed until the desired size reachedfinally, if the size is larger than the limit defined by the
maximum-cache-disk-usageconfig the oldest cache entries are removed until the desired size reached
- directory()
Return the path to the current (cache) directory.
- Returns:
The cache directory when
cache-policyis “user” or “temporary”. The temporary directory whencache-policyis “off”.- Return type:
str
- entries(*args, **kwargs)
Dump the entries stored in the cache.
Does not work when the
cache-policyis “off”.- Returns:
One dict per cache entry.
- Return type:
listofdict
- property policy
Get the current cache policy.
- Type:
CachePolicy
- purge(*args, **kwargs)
Delete entries from the cache.
Does not work when the
cache-policyis “off”.- Parameters:
**kwargs (
dict, optional) –Other keyword arguments:
- matcher: callable
Method to match the cache entries to delete. Its only argument is a cache entry and should return True if the entry is to be deleted.
Examples
Delete all entries.
>>> from earthkit.data import cache >>> cache.purge()
Delete all entries where the “owner” is “test_cache”.
>>> from earthkit.data import cache >>> cache.purge(matcher=lambda e: ["owner"] == "test_cache")
- size(*args, **kwargs)
Return the total number of bytes stored in the cache.
Does not work when the
cache-policyis “off”.
- summary_dump_database(*args, **kwargs)
Return the number of items and total size of the cache.
Does not work when the
cache-policyis “off”.- Returns:
num (
int) – number of items in the cachesize (
int) – total number of bytes stored in the cache
Examples
>>> from earthkit.data import cache >>> cache.summary_dump_database() (40, 846785699)