fsl.utils.cache¶
This module provides the Cache class., a simple in-memory cache.
-
exception
fsl.utils.cache.Expired[source]¶ Bases:
ExceptionExceptionraised by theCache.get()metho when an attempt is made to access a cache item that has expired.-
__module__= 'fsl.utils.cache'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
fsl.utils.cache.CacheItem(key, value, expiry=0)[source]¶ Bases:
objectInternal container class used to store
Cacheitems.-
__init__(key, value, expiry=0)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__dict__= mappingproxy({'__module__': 'fsl.utils.cache', '__doc__': 'Internal container class used to store :class:`Cache` items. ', '__init__': <function CacheItem.__init__>, '__dict__': <attribute '__dict__' of 'CacheItem' objects>, '__weakref__': <attribute '__weakref__' of 'CacheItem' objects>})¶
-
__module__= 'fsl.utils.cache'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
fsl.utils.cache.Cache(maxsize=100, lru=False)[source]¶ 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.
-
__init__(maxsize=100, lru=False)[source]¶ Create a
Cache.- Parameters
maxsize – Maximum number of items allowed in the
Cachebefore it starts dropping old itemslru – (least recently used) If
False(the default), items are dropped according to their insertion time. Otherwise, items are dropped according to their most recent access time.
-
put(key, value, expiry=0)[source]¶ 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)[source]¶ 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.
-
__contains__(key)[source]¶ Check whether an item is in the cache. Note that the item may be in the cache, but it may be expired.
-
__parseDefault(*args, **kwargs)¶ Used by the
get()method. Parses thedefaultargument, which may be specified as either a positional or keyword argumnet.- Returns
A tuple containing two values:
Trueif a default argument was specified,Falseotherwise.The specified default value, or
Noneif it wasn’t specified.
-
__dict__= mappingproxy({'__module__': 'fsl.utils.cache', '__doc__': 'The ``Cache`` is a simple in-memory cache built on a\n ``collections.OrderedDict``. The ``Cache`` class has the following\n features:\n\n - When an item is added to a full cache, the oldest entry is\n automatically dropped.\n\n - Expiration times can be specified for individual items. If a request\n is made to access an expired item, an :class:`Expired` exception is\n raised.\n ', '__init__': <function Cache.__init__>, 'put': <function Cache.put>, 'get': <function Cache.get>, 'clear': <function Cache.clear>, '__len__': <function Cache.__len__>, '__getitem__': <function Cache.__getitem__>, '__setitem__': <function Cache.__setitem__>, '__contains__': <function Cache.__contains__>, '_Cache__parseDefault': <function Cache.__parseDefault>, '__dict__': <attribute '__dict__' of 'Cache' objects>, '__weakref__': <attribute '__weakref__' of 'Cache' objects>})¶
-
__module__= 'fsl.utils.cache'¶
-
__weakref__¶ list of weak references to the object (if defined)