Sentinels
Sentinel values that let the @cache_results decorator tell a cached.
None from a cache miss.
CACHE_MISS_SENTINELis a unique object, passed as the default of a cache read. Getting it back means the key is not cached.CACHE_NONE_SENTINELis the string that is stored in place of aNoneresult, because many cache backends can’t tell a storedNonefrom a missing key.
value = cache.get(key, CACHE_MISS_SENTINEL)
if value is CACHE_MISS_SENTINEL:
... # not cached
elif value == CACHE_NONE_SENTINEL:
value = None # a cached None
- cache_results.sentinels.CACHE_MISS_SENTINEL = <CacheSentinel: CACHE_MISS>
The default of a cache read, returned only when the key is not cached.
- cache_results.sentinels.CACHE_NONE_SENTINEL = 'CacheSentinel("CACHE_NONE")'
The value stored in place of a
Noneresult.
- class cache_results.sentinels.CacheSentinel(name: str)[source]
Bases:
objectA unique, named marker object.
Two sentinels are never equal unless they are the same object, so one can be passed as the default of a cache read without colliding with any cached value.
- Parameters:
name (str) – The name shown by
str()andrepr().