fictive.cache.abstract module

Provides a base class for automatically managed read-through cacheing behavior

Subclasses should provide a backing store and methods for fetching a new value

Classes

AbstractCache

An abstract class representing a single-level cache interface

class fictive.cache.abstract.AbstractCache(*args, fetch_impl=None, **kwargs)[source]

Bases: object

An abstract class representing a single-level cache interface

This interface provides four basic actions (_fetch_impl, _read_impl, _set_impl, and _delete_impl) for implementing the interaction between the cache interface and a backing store. Subclasses for specific cache backing store types should generally override one or more of these methods.

Additionally, each of the four actions has an associated ‘private’ dispatch method (_dispatch_fetch, _dispatch_read, _dispatch_set, and _dispatch__delete, respectively) that controlls when and how the interface methods will be invoked. Mixins or subclasses that want to supplement or override generic cache behavior, or alter the ways in which the basic actions interoperate, would probably want to override one or more of these methods.

The interface also provides a value and delete methods by which client code can access and clear the cached value, and a fetch decorator by which client code can set the callable that will ‘refresh’ the cache from an external value

ANY_VALUE = <object object>
exception CacheError[source]

Bases: Exception

Generic AbstractCache exception class

exception CacheFetchError[source]

Bases: fictive.cache.abstract.AbstractCache.CacheError

Raised when an external value could nto be obtained

exception CacheMissError[source]

Bases: fictive.cache.abstract.AbstractCache.CacheError

Raised when a value is not present in the cache

exception CacheWriteError[source]

Bases: fictive.cache.abstract.AbstractCache.CacheError

Raised when a value cannot be written to the cache

IDENTITY_TRANSFORM = <fictive.transform.Transform object>
VALUE_TRANSFORM: fictive.transform.Transform = <fictive.transform.Transform object>

Transform applied to present values to calling code

__init__(*args, fetch_impl=None, **kwargs)[source]
Parameters

fetch_impl (callable) – if provided, this callable will be invoked by _dispatch_fetch (rather than the class’s _fetch_impl method). The call siganture of fetch_impl must accept this instance as a first positional argument.

delete_value(cache_value, *args, **kwargs)[source]

interface to delete the stored value if it is equal to cache_value

property fetch_impl

allow for overriding _fetch_impl after initialization

get_value(*args, **kwargs)[source]

client interface to access the cache; automatically fetches if needed

set_value(value, *args, **kwargs)[source]

client interface to set the cache

property value

simple property-based interface for default cache behavior