Cache Module

Cache module.

class pepperpy.cache.CacheEntry(value, expires_at=None, metadata=None)[source]

Bases: object

Cache entry.

Parameters:
value: Any
expires_at: Optional[datetime] = None
metadata: Optional[Dict[str, Any]] = None
class pepperpy.cache.CacheConfig(ttl=None, max_size=None)[source]

Bases: object

Cache configuration.

Parameters:
  • ttl (int | None)

  • max_size (int | None)

ttl: Optional[int] = None
max_size: Optional[int] = None
class pepperpy.cache.Cache[source]

Bases: ABC

Cache interface.

abstract get(key)[source]

Get value from cache.

Parameters:

key (str) – Cache key.

Return type:

Optional[CacheEntry]

Returns:

Cache entry or None if not found.

abstract set(key, value, expires_at=None, metadata=None)[source]

Set value in cache.

Parameters:
Return type:

CacheEntry

Returns:

Cache entry.

abstract delete(key)[source]

Delete value from cache.

Parameters:

key (str) – Cache key.

Return type:

Optional[CacheEntry]

Returns:

Deleted cache entry or None if not found.

abstract clear()[source]

Clear cache.

Return type:

None

class pepperpy.cache.MemoryCache(config=None)[source]

Bases: Cache

Memory cache implementation.

Parameters:

config (CacheConfig | None)

__init__(config=None)[source]

Initialize memory cache.

Parameters:

config (Optional[CacheConfig]) – Cache configuration.

Return type:

None

get(key)[source]

Get value from cache.

Parameters:

key (str) – Cache key.

Return type:

Optional[CacheEntry]

Returns:

Cache entry or None if not found.

set(key, value, expires_at=None, metadata=None)[source]

Set value in cache.

Parameters:
Return type:

CacheEntry

Returns:

Cache entry.

delete(key)[source]

Delete value from cache.

Parameters:

key (str) – Cache key.

Return type:

Optional[CacheEntry]

Returns:

Deleted cache entry or None if not found.

clear()[source]

Clear cache.

Return type:

None