Smarter Cache Sentinel
smarter.lib.cache.cache_sentinel
This module defines sentinel objects for robust cache state management in the Smarter framework.
Key Features:
Provides the
CacheSentinelclass for distinguishing between explicitNonevalues and cache misses.Exports
CACHE_MISS_SENTINEL(a unique object) andCACHE_NONE_SENTINEL(a string sentinel) for use in cache decorators and wrappers.Ensures reliable cache semantics when cached functions may return
Noneor when differentiating between missing and present-but-None values.
Usage Example:
from smarter.lib.cache.cache_sentinel import CACHE_MISS_SENTINEL
value = cache.get(key, CACHE_MISS_SENTINEL)
if value is CACHE_MISS_SENTINEL:
# Handle cache miss
...
elif value is None:
# Handle cached None
...
See the CacheSentinel class docstring for more details.