Problem
CacheChecker checks whether an item exists in a document store’s cache_field, but it has no expiration support. Once a document is cached, it is treated as a hit indefinitely, even when the data is stale.
Description
Add optional TTL support to CacheChecker:
ttl: timedelta | None = None
time_field: str = "cached_at"
When ttl is configured, a matching document should count as a cache hit only if:
datetime.now() - document.meta[time_field] < ttl
Documents with a missing timestamp or an expired timestamp should be treated as misses, just like items that are not cached.
Setting ttl=None should preserve the current behavior for full backward compatibility. The same expiration logic should apply to both run() and run_async().
Example:
from datetime import timedelta
cache_checker = CacheChecker(
document_store,
cache_field="url",
ttl=timedelta(hours=24),
)
Alternatives considered
A separate TTLCacheChecker component or subclass was considered, but extending CacheChecker with optional parameters seems simpler and avoids duplicating existing cache-checking behavior.
Additional context
The feature should include tests for fresh entries, expired entries, missing timestamps, synchronous and asynchronous execution, serialization, and backward compatibility when ttl=None.
If this feature is of interest, I would be happy to work on the implementation and add the corresponding tests and documentation.
Problem
CacheCheckerchecks whether an item exists in a document store’scache_field, but it has no expiration support. Once a document is cached, it is treated as a hit indefinitely, even when the data is stale.Description
Add optional TTL support to
CacheChecker:When
ttlis configured, a matching document should count as a cache hit only if:Documents with a missing timestamp or an expired timestamp should be treated as misses, just like items that are not cached.
Setting
ttl=Noneshould preserve the current behavior for full backward compatibility. The same expiration logic should apply to bothrun()andrun_async().Example:
Alternatives considered
A separate
TTLCacheCheckercomponent or subclass was considered, but extendingCacheCheckerwith optional parameters seems simpler and avoids duplicating existing cache-checking behavior.Additional context
The feature should include tests for fresh entries, expired entries, missing timestamps, synchronous and asynchronous execution, serialization, and backward compatibility when
ttl=None.If this feature is of interest, I would be happy to work on the implementation and add the corresponding tests and documentation.