DiskCache

DiskCache(seed: str | int)

Implementation of AbstractCache using the DiskCache library.
This class provides a concrete implementation of the AbstractCache interface using the diskcache library for caching data on disk.
Attributes:
cache (diskcache.Cache): The DiskCache instance used for caching.
Methods:
init(self, seed): Initializes the DiskCache with the given seed.
get(self, key, default=None): Retrieves an item from the cache.
set(self, key, value): Sets an item in the cache.
close(self): Closes the cache.
enter(self): Context management entry.
exit(self, exc_type, exc_value, traceback): Context management exit.
Initialize the DiskCache instance.

Parameters:
NameDescription
seedType: str | int

Instance Methods

close

close(self) -> None

Close the cache.
Perform any necessary cleanup, such as closing file handles or releasing resources.


get

get(
    self,
    key: str,
    default: Any | None = None
) -> Any | None

Retrieve an item from the cache.

Parameters:
NameDescription
keyThe key identifying the item in the cache.

Type: str
defaultThe default value to return if the key is not found.

Defaults to None.

Type: Any | None

Default: None
Returns:
TypeDescription
Any | NoneThe value associated with the key if found, else the default value.

set

set(
    self,
    key: str,
    value: Any
) -> None

Set an item in the cache.

Parameters:
NameDescription
keyThe key under which the item is to be stored.

Type: str
valueThe value to be stored in the cache.

Type: Any