pyignite.aio_cache module

class pyignite.aio_cache.AioCache(client: AioClient, name: str, expiry_policy: pyignite.datatypes.expiry_policy.ExpiryPolicy = None)

Bases: pyignite.cache.BaseCache

Ignite cache abstraction. Users should never use this class directly, but construct its instances with create_cache(), get_or_create_cache() or get_cache() methods instead. See this example on how to do it.

__init__(client: AioClient, name: str, expiry_policy: pyignite.datatypes.expiry_policy.ExpiryPolicy = None)

Initialize async cache object. For internal use.

Parameters
  • client – Async Ignite client,

  • name – Cache name.

async clear(keys: Optional[list] = None, timeout: Union[int, float] = 0)

Clears the cache without notifying listeners or cache writers.

Parameters
  • keys – (optional) list of cache keys or (key, key type hint) tuples to clear (default: clear all).

  • timeout – (optional) request timeout.

async clear_key(key, key_hint: object = None, timeout: Union[int, float] = 0)

Clears the cache key without notifying listeners or cache writers.

Parameters
  • key – key for the cache entry,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • timeout – (optional) request timeout.

async clear_keys(keys: Iterable, timeout: Union[int, float] = 0)

Clears the cache key without notifying listeners or cache writers.

Parameters
  • keys – a list of keys or (key, type hint) tuples

  • timeout – (optional) request timeout.

async contains_key(key, key_hint=None, timeout: Union[int, float] = 0) bool

Returns a value indicating whether given key is present in cache.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • timeout – (optional) request timeout,

Returns

boolean True when key is present, False otherwise.

async contains_keys(keys: Iterable, timeout: Union[int, float] = 0) bool

Returns a value indicating whether all given keys are present in cache.

Parameters
  • keys – a list of keys or (key, type hint) tuples,

  • timeout – (optional) request timeout,

Returns

boolean True when all keys are present, False otherwise.

async destroy(timeout: Union[int, float] = 0)

Destroys cache with a given name.

Parameters

timeout – (optional) request timeout.

async get(key, key_hint: object = None, timeout: Union[int, float] = 0) Any

Retrieves a value from cache by key.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • timeout – (optional) request timeout.

Returns

value retrieved.

async get_all(keys: list, timeout: Union[int, float] = 0) dict

Retrieves multiple key-value pairs from cache.

Parameters
  • keys – list of keys or tuples of (key, key_hint),

  • timeout – (optional) request timeout,

Returns

a dict of key-value pairs.

async get_and_put(key, value, key_hint=None, value_hint=None, timeout: Union[int, float] = 0) Any

Puts a value with a given key to cache, and returns the previous value for that key, or null value if there was not such key.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout,

Returns

old value or None.

async get_and_put_if_absent(key, value, key_hint=None, value_hint=None, timeout: Union[int, float] = 0)

Puts a value with a given key to cache only if the key does not already exist.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout,

Returns

old value or None.

async get_and_remove(key, key_hint=None, timeout: Union[int, float] = 0) Any

Removes the cache entry with specified key, returning the value.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • timeout – (optional) request timeout,

Returns

old value or None.

async get_and_replace(key, value, key_hint=None, value_hint=None, timeout: Union[int, float] = 0) Any

Puts a value with a given key to cache, returning previous value for that key, if and only if there is a value currently mapped for that key.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout,

Returns

old value or None.

async get_size(peek_modes=None, timeout: Union[int, float] = 0)

Gets the number of entries in cache.

Parameters
  • peek_modes – (optional) limit count to near cache partition (PeekModes.NEAR), primary cache (PeekModes.PRIMARY), or backup cache (PeekModes.BACKUP). Defaults to primary cache partitions (PeekModes.PRIMARY),

  • timeout – (optional) request timeout,

Returns

integer number of cache entries.

async put(key, value, key_hint: object = None, value_hint: object = None, timeout: Union[int, float] = 0)

Puts a value with a given key to cache (overwriting existing value if any).

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout.

async put_all(pairs: dict, timeout: Union[int, float] = 0)

Puts multiple key-value pairs to cache (overwriting existing associations if any).

Parameters
  • pairs – dictionary type parameters, contains key-value pairs to save. Each key or value can be an item of representable Python type or a tuple of (item, hint),

  • timeout – (optional) request timeout.

async put_if_absent(key, value, key_hint=None, value_hint=None, timeout: Union[int, float] = 0)

Puts a value with a given key to cache only if the key does not already exist.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout,

async remove_all(timeout: Union[int, float] = 0)

Removes all cache entries, notifying listeners and cache writers.

Parameters

timeout – (optional) request timeout.

async remove_if_equals(key, sample, key_hint=None, sample_hint=None, timeout: Union[int, float] = 0)

Removes an entry with a given key if provided value is equal to actual value, notifying listeners and cache writers.

Parameters
  • key – key for the cache entry,

  • sample – a sample to compare the stored value with,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • sample_hint – (optional) Ignite data type, for whic the given sample should be converted,

  • timeout – (optional) request timeout.

async remove_key(key, key_hint=None, timeout: Union[int, float] = 0)

Clears the cache key without notifying listeners or cache writers.

Parameters
  • key – key for the cache entry,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • timeout – (optional) request timeout.

async remove_keys(keys: list, timeout: Union[int, float] = 0)

Removes cache entries by given list of keys, notifying listeners and cache writers.

Parameters
  • keys – list of keys or tuples of (key, key_hint) to remove,

  • timeout – (optional) request timeout.

async replace(key, value, key_hint: object = None, value_hint: object = None, timeout: Union[int, float] = 0)

Puts a value with a given key to cache only if the key already exist.

Parameters
  • key – key for the cache entry. Can be of any supported type,

  • value – value for the key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout.

async replace_if_equals(key, sample, value, key_hint=None, sample_hint=None, value_hint=None, timeout: Union[int, float] = 0) Any

Puts a value with a given key to cache only if the key already exists and value equals provided sample.

Parameters
  • key – key for the cache entry,

  • sample – a sample to compare the stored value with,

  • value – new value for the given key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

  • sample_hint – (optional) Ignite data type, for whic the given sample should be converted

  • value_hint – (optional) Ignite data type, for which the given value should be converted,

  • timeout – (optional) request timeout,

Returns

boolean True when key is present, False otherwise.

scan(page_size: int = 1, partitions: int = - 1, local: bool = False, timeout: Union[int, float] = 0) pyignite.cursors.AioScanCursor

Returns all key-value pairs from the cache, similar to get_all, but with internal pagination, which is slower, but safer.

Parameters
  • page_size – (optional) page size. Default size is 1 (slowest and safest),

  • partitions – (optional) number of partitions to query (negative to query entire cache),

  • local – (optional) pass True if this query should be executed on local node only. Defaults to False,

Returns

async scan query cursor

async settings(timeout: Union[int, float] = 0) Optional[dict]

Lazy Cache settings. See the example of reading this property.

All cache properties are documented here: Cache Properties.

Parameters

timeout – (optional) request timeout.

Returns

dict of cache properties and their values.

async pyignite.aio_cache.create_cache(client: AioClient, settings: Union[str, dict]) AioCache
async pyignite.aio_cache.get_cache(client: AioClient, settings: Union[str, dict]) AioCache
async pyignite.aio_cache.get_or_create_cache(client: AioClient, settings: Union[str, dict]) AioCache