fsl.utils.cache
¶
This module provides the Cache
class., a simple in-memory cache.
-
exception
fsl.utils.cache.
Expired
¶ Bases:
Exception
Exception
raised 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:
object
Internal container class used to store
Cache
items.
-
class
fsl.utils.cache.
Cache
(maxsize=100)¶ Bases:
object
The
Cache
is a simple in-memory cache built on acollections.OrderedDict
. TheCache
class 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
Expired
exception 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
0
will 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.