pyignite.cache module

class pyignite.cache.BaseCache(client: BaseClient, name: str)
__init__(client: BaseClient, name: str)

Initialize self. See help(type(self)) for accurate signature.

cache_id

Cache ID.

Returns:integer value of the cache ID.
client
Returns:Client object, through which the cache is accessed.
name
Returns:cache name string.
class pyignite.cache.Cache(client: Client, name: str)

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: Client, name: str)

Initialize cache object. For internal use.

Parameters:
  • client – Ignite client,
  • name – Cache name.
cache_id

Cache ID.

Returns:integer value of the cache ID.
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
client
Returns:Client object, through which the cache is accessed.
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) → list

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.
name
Returns:cache name string.
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.ScanCursor

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:

Scan query cursor.

select_row(query_str: str, page_size: int = 1, query_args: Union[list, NoneType] = None, distributed_joins: bool = False, replicated_only: bool = False, local: bool = False, timeout: int = 0) → pyignite.cursors.SqlCursor

Executes a simplified SQL SELECT query over data stored in the cache. The query returns the whole record (key and value).

Parameters:
  • query_str – SQL query string,
  • page_size – (optional) cursor page size. Default is 1, which means that client makes one server call per row,
  • query_args – (optional) query arguments,
  • distributed_joins – (optional) distributed joins. Defaults to False,
  • replicated_only – (optional) whether query contains only replicated tables or not. Defaults to False,
  • local – (optional) pass True if this query should be executed on local node only. Defaults to False,
  • timeout – (optional) non-negative timeout value in ms. Zero disables timeout (default),
Returns:

Sql cursor.

settings

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.cache.create_cache(client: Client, settings: Union[str, dict]) → Cache
pyignite.cache.get_cache(client: Client, settings: Union[str, dict]) → Cache
pyignite.cache.get_or_create_cache(client: Client, settings: Union[str, dict]) → Cache