pynenc.arg_cache.base_arg_cache

Module Contents

Classes

RunnerCacheKeys

Keys used in runner cache.

BaseArgCache

Base class for argument caching system.

API

class pynenc.arg_cache.base_arg_cache.RunnerCacheKeys[source]

Bases: enum.StrEnum

Keys used in runner cache.

Initialization

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

ARG_CACHE_ID

‘auto(…)’

ARG_CACHE_HASH

‘auto(…)’

ARG_CACHE_FINGERPRINT

‘auto(…)’

ARG_CACHE_KEY

‘auto(…)’

ARG_CACHE_DESERIALIZED

‘auto(…)’

class pynenc.arg_cache.base_arg_cache.BaseArgCache(app: pynenc.app.Pynenc)[source]

Bases: abc.ABC

Base class for argument caching system.

Caches large serialized arguments to avoid repeatedly sending them between tasks. Subclasses should implement the actual storage mechanism.

Initialization

Initialize with app reference.

_initialize_caches() None[source]

Initialize cache sections if they don’t exist. Safe to call multiple times - won’t overwrite existing data. Works for both local and runner caches.

_get_cache(key: pynenc.arg_cache.base_arg_cache.RunnerCacheKeys) dict[source]

Get the appropriate cache dictionary. Ensures caches are initialized.

Parameters:

key (RunnerCacheKeys) – The cache section to access

Returns:

The cache dictionary to use

property _obj_id_cache: dict[int, str]

Object ID cache with fallback.

property _hash_cache: dict[int, str]

Hash cache with fallback.

property _fingerprint_cache: dict[tuple[str, int], str]

Fingerprint cache with fallback.

property _key_cache: dict[str, str]

Key cache with fallback.

property _deserialized_cache: dict[str, Any]

Deserialized object cache with fallback.

conf() pynenc.conf.config_arg_cache.ConfigArgCache

Get the argument cache configuration.

_check_object_identity(obj: Any) str | None[source]

Check if object is already cached by identity.

_check_object_hash(obj: Any) tuple[str | None, int][source]

Try to get cached value using object hash. Returns (cached_key, obj_id) or (None, obj_id).

_check_fingerprint(serialized: str, obj_id: int, obj: Any) str | None[source]

Check if serialized content matches by fingerprint.

_check_exact_match(serialized: str, obj_id: int, obj: Any) tuple[str | None, tuple[str, int]][source]

Check if exact serialized content is cached. Returns (cached_key, fingerprint) or (None, fingerprint).

_store_new_value(serialized: str, obj_id: int, obj: Any, fingerprint: tuple[str, int]) str[source]

Store new value and update all caches.

serialize(obj: Any, disable_cache: bool = False) str[source]

Serialize an object, potentially caching if it meets size requirements.

Parameters:
  • obj (Any) – Object to serialize

  • disable_cache (bool) – If True, skips caching regardless of size

Returns:

Either the serialized string or a cache key

deserialize(data: str) Any[source]

Deserialize data, checking if it’s a cache key first.

Parameters:

data (str) – Data to deserialize (might be a cache key)

Returns:

The deserialized object

is_cache_key(value: str) bool[source]

Check if a string is a cache key.

_generate_key(value: str) str[source]

Generate a cache key for a value.

_update_obj_id_cache(obj_id: int, key: str) None[source]

Update the object ID cache with LRU eviction.

_update_hash_cache(obj: Any, key: str) None[source]

Update the hash cache with LRU eviction if object is hashable.

_update_fingerprint_cache(fingerprint: tuple[str, int], key: str) None[source]

Update the fingerprint cache with LRU eviction.

_update_key_cache(serialized: str, key: str) None[source]

Update the key cache with LRU eviction.

_update_deserialized_cache(key: str, obj: Any) None[source]

Update the value cache with LRU eviction.

purge() None[source]

Clear all cached arguments.

Should clear both the in-memory caches and the storage backend.

abstract _store(key: str, value: str) None[source]

Store a key value pair in the cache

Parameters:
  • key (str) – The cache key

  • value (str) – The string value to cache

Returns:

Cache key for the stored value

abstract _retrieve(key: str) str[source]

Retrieve a serialized value from the cache by its key.

Parameters:

key (str) – The cache key

Returns:

The cached serialized value

Raises:

KeyError – If the key is not found

abstract _purge() None[source]

Clear all cached arguments.