pygridgain.aio_cache module¶
- class pygridgain.aio_cache.AioCache(client: AioClient, name: str, expiry_policy: ExpiryPolicy = None)¶
Bases:
BaseCacheIgnite cache abstraction. Users should never use this class directly, but construct its instances with
create_cache(),get_or_create_cache()orget_cache()methods instead. See this example on how to do it.- __init__(client: AioClient, name: str, expiry_policy: ExpiryPolicy = None)¶
Initialize async cache object. For internal use.
- Parameters:
client – Async Ignite client,
name – Cache name.
- async clear(keys: list | None = 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).
- async 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,
- async clear_keys(keys: Iterable)¶
Clears the cache key without notifying listeners or cache writers.
- Parameters:
keys – a list of keys or (key, type hint) tuples
- async 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.
- async contains_keys(keys: Iterable) 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.
- async destroy()¶
Destroys cache with a given name.
- async 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.
- async 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.
- async 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.
- async 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.
- async 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.
- async 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.
- async 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.
- async 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.
- async 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),
- async 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.
- async remove_all()¶
Removes all cache entries, notifying listeners and cache writers.
- async 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.
- async 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,
- async 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.
- async 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.
- async 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) 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() dict | None¶
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.
- vector(type_name: str, field: str, clause_vector: List[float], k: int, threshold: float, page_size: int = 1) AioVectorCursor¶
Ignite supports vector queries based on Apache Lucene engine.
- Parameters:
type_name – Name of the type.
field – Name of the field.
clause_vector – Search vector.
k – [K]NN, how many vectors to return.
page_size – (optional) page size. Default size is 1 (slowest and safest),
- Returns:
Scan query cursor.