abstract#

Implement an abstract cache backend. You can customize your own cache backend.

class pynamodb_mate.patterns.cache.abstract.CacheRecord(value: bytes, expire: int, update_ts: int)[source]#

Represent a cache record.

Parameters:
  • key – the cache key

  • value – the binary view of the original value

  • expire – cache expire time, in seconds

  • update_ts – last update timestamp

class pynamodb_mate.patterns.cache.abstract.AbstractCache(*args, **kwds)[source]#

An abstract cache class regardless of the backend.

abstract serialize(value: VALUE) bytes[source]#

Abstract serialization function that convert the original value to binary data.

abstract deserialize(value: bytes) VALUE[source]#

Abstract deserialization function the recover the original value from binary data.

clear_all()[source]#

Disable all records in cache.

clear_expired()[source]#

Disable all expired records in cache.

set(key: str, value: VALUE, expire: int = 0)[source]#

Store object in cache.

Parameters:
  • key – cache key.

  • value – the object you stored in cache.

  • expire – Time-to-live in seconds.

get(key: str) Optional[VALUE][source]#

Get object from cache.

Parameters:

key – cache key

Returns:

the cached object.