fsl.utils.cache¶
This module provides the Cache class., a simple in-memory cache.
-
exception
fsl.utils.cache.Expired¶ Bases:
ExceptionExceptionraised by theCache.get()metho when an attempt is made to access a cache item that has expired.
-
class
fsl.utils.cache.CacheItem(key, value, expiry=0)¶ Bases:
objectInternal container class used to store
Cacheitems.
-
class
fsl.utils.cache.Cache(maxsize=100)¶ Bases:
objectThe
Cacheis a simple in-memory cache built on acollections.OrderedDict. TheCacheclass has the following features:- When an item is added to a full cache, the oldest entry is automatically dropped.
- Expiration times can be specified for individual items. If a request
is made to access an expired item, an
Expiredexception is raised.
-
put(key, value, expiry=0)¶ Put an item in the cache.
Parameters: - key – Item identifier (must be hashable).
- value – The item to store.
- expiry – Expiry time in seconds. An item with an expiry time of
0will not expire.
-
get(key, *args, **kwargs)¶ Get an item from the cache.
Parameters: - key – Item identifier.
- default – Default value to return if the item is not in the cache, or has expired.
-
clear()¶ Remove all items from the cache.