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 CacheSentinel class for distinguishing between explicit None values and cache misses.

  • Exports CACHE_MISS_SENTINEL (a unique object) and CACHE_NONE_SENTINEL (a string sentinel) for use in cache decorators and wrappers.

  • Ensures reliable cache semantics when cached functions may return None or 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.