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.
clear(keys: Union[list, NoneType] = None)

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).
clear_key(key, key_hint: object = None)

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,
clear_keys(keys: Iterable[T_co])

Clears the cache key without notifying listeners or cache writers.

Parameters:keys – a list of keys or (key, type hint) tuples
contains_key(key, key_hint=None) → 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,
Returns:

boolean True when key is present, False otherwise.

contains_keys(keys: Iterable[T_co]) → bool

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

Parameters:keys – a list of keys or (key, type hint) tuples,
Returns:boolean True when all keys are present, False otherwise.
destroy()

Destroys cache with a given name.

get(key, key_hint: object = None) → 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,
Returns:

value retrieved.

get_all(keys: list) → dict

Retrieves multiple key-value pairs from cache.

Parameters:keys – list of keys or tuples of (key, key_hint),
Returns:a dict of key-value pairs.
get_and_put(key, value, key_hint=None, value_hint=None) → 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.
Returns:

old value or None.

get_and_put_if_absent(key, value, key_hint=None, value_hint=None)

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,
Returns:

old value or None.

get_and_remove(key, key_hint=None) → 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,
Returns:

old value or None.

get_and_replace(key, value, key_hint=None, value_hint=None) → 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.
Returns:

old value or None.

get_size(peek_modes=None)

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),
Returns:integer number of cache entries.
put(key, value, key_hint: object = None, value_hint: object = None)

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.
put_all(pairs: dict)

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),
put_if_absent(key, value, key_hint=None, value_hint=None)

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.
remove_all()

Removes all cache entries, notifying listeners and cache writers.

remove_if_equals(key, sample, key_hint=None, sample_hint=None)

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.
remove_key(key, key_hint=None)

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,
remove_keys(keys: list)

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.
replace(key, value, key_hint: object = None, value_hint: object = None)

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.
replace_if_equals(key, sample, value, key_hint=None, sample_hint=None, value_hint=None) → 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,
Returns:

boolean True when key is present, False otherwise.

scan(page_size: int = 1, partitions: int = -1, local: bool = False) → 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

settings() → Union[dict, NoneType]

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

All cache properties are documented here: Cache Properties.

Returns:dict of cache properties and their values.
pyignite.aio_cache.create_cache(client: AioClient, settings: Union[str, dict]) → AioCache
pyignite.aio_cache.get_cache(client: AioClient, settings: Union[str, dict]) → AioCache
pyignite.aio_cache.get_or_create_cache(client: AioClient, settings: Union[str, dict]) → AioCache