data.core.caching

Classes

Cache

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-policy is “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-size config the oldest cache entries are removed until the desired size reached

  • finally, if the size is larger than the limit defined by the maximum-cache-disk-usage config 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-policy is “user” or “temporary”. The temporary directory when cache-policy is “off”.

Return type:

str

entries(*args, **kwargs)

Dump the entries stored in the cache.

Does not work when the cache-policy is “off”.

Returns:

One dict per cache entry.

Return type:

list of dict

property policy

Get the current cache policy.

Type:

CachePolicy

purge(*args, **kwargs)

Delete entries from the cache.

Does not work when the cache-policy is “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-policy is “off”.

summary_dump_database(*args, **kwargs)

Return the number of items and total size of the cache.

Does not work when the cache-policy is “off”.

Returns:

  • num (int) – number of items in the cache

  • size (int) – total number of bytes stored in the cache

Examples

>>> from earthkit.data import cache
>>> cache.summary_dump_database()
(40, 846785699)