akkudoktoreos.core.cache.CacheEnergyManagementStore

class akkudoktoreos.core.cache.CacheEnergyManagementStore(*args: Any, **kwargs: Any)

Bases: SingletonMixin

Singleton-based in-memory LRU (Least Recently Used) cache.

This cache is shared across the application to store results of decorated methods or functions during energy management runs.

Energy management tasks shall clear the cache at the start of the energy management task.

The cache uses an LRU eviction strategy, storing up to 100 items, with the oldest items being evicted once the cache reaches its capacity.

__init__(*args: Any, **kwargs: Any) None

Initializes the CacheEnergyManagementStore instance with default parameters.

The cache uses an LRU eviction strategy with a maximum size of 100 items. This cache is a singleton, meaning only one instance will exist throughout the application lifecycle.

Example

>>> cache = CacheEnergyManagementStore()

Methods

__init__(*args, **kwargs)

Initializes the CacheEnergyManagementStore instance with default parameters.

clear()

Clears the cache, removing all stored items.

reset_instance()

Resets the singleton instance, forcing it to be recreated on next access.

Attributes

cache

hit_count

last_event

last_key

last_value

miss_count

cache: ClassVar[LRUCache] = cachebox._cachebox.LRUCache[0/100]({})
last_event: ClassVar[int | None] = None
last_key: ClassVar[Any] = None
last_value: ClassVar[Any] = None
hit_count: ClassVar[int] = 0
miss_count: ClassVar[int] = 0
__init__(*args: Any, **kwargs: Any) None

Initializes the CacheEnergyManagementStore instance with default parameters.

The cache uses an LRU eviction strategy with a maximum size of 100 items. This cache is a singleton, meaning only one instance will exist throughout the application lifecycle.

Example

>>> cache = CacheEnergyManagementStore()
__getattr__(name: str) Any

Propagates method calls to the cache object.

This method allows you to call methods on the underlying cache object, and it will delegate the call to the cache’s corresponding method.

Parameters:

name (str) – The name of the method being called.

Returns:

A method bound to the cache object.

Return type:

Callable

Raises:

AttributeError – If the cache object does not have the requested method.

Example

>>> result = cache.get("key")
__getitem__(key: Any) Any

Retrieves an item from the cache by its key.

Parameters:

key (Any) – The key used for subscripting to retrieve an item.

Returns:

The value corresponding to the key in the cache.

Return type:

Any

Raises:

KeyError – If the key does not exist in the cache.

Example

>>> value = cache["user_data"]
__setitem__(key: Any, value: Any) None

Stores an item in the cache.

Parameters:
  • key (Any) – The key used to store the item in the cache.

  • value (Any) – The value to store.

Example

>>> cache["user_data"] = {"name": "Alice", "age": 30}
__len__() int

Returns the number of items in the cache.

__repr__() str

Provides a string representation of the CacheEnergyManagementStore object.

clear() None

Clears the cache, removing all stored items.

This method propagates the clear method call to the underlying cache object, ensuring that the cache is emptied when necessary (e.g., at the end of the energy management system run).

Example

>>> cache.clear()
static __new__(cls: Type[SingletonMixin], *args: Any, **kwargs: Any) SingletonMixin

Creates or returns the singleton instance of the class.

Ensures thread-safe instance creation by locking during the first instantiation.

Parameters:
  • *args – Positional arguments for instance creation (ignored if instance exists).

  • **kwargs – Keyword arguments for instance creation (ignored if instance exists).

Returns:

The singleton instance of the derived class.

Return type:

SingletonMixin

classmethod reset_instance() None

Resets the singleton instance, forcing it to be recreated on next access.