Skip to content

test(cache): add comprehensive tests for cache invalidation (#711) - #818

Merged
gelluisaac merged 2 commits into
Traqora:mainfrom
mhaye9545:test/711-cache-invalidation-tests
Sep 5, 2026
Merged

gelluisaac merged 2 commits into
Traqora:mainfrom
mhaye9545:test/711-cache-invalidation-tests

Conversation

@mhaye9545

Copy link
Copy Markdown
Contributor

Closes #711.

Summary

Adds comprehensive tests for cache invalidation across astroml/cache, covering:

  1. TTL Expiry:
    • _MemoryGraphStore lazy eviction past expiration timestamp.
    • Cache miss tracking and automatic recompute of fresh values when TTL expires.
  2. Stale Writes:
    • Overwriting existing keys with updated graph/computation data returning fresh values instead of stale cached data.
  3. Explicit Purge:
    • Key-level invalidation (invalidate(prefix, key) / delete(key)).
    • Prefix-level invalidation (invalidate(prefix) / delete_pattern(pattern)).
    • Global purge (cache.clear() / clear_all_caches() / invalidate_graph_cache()).
  4. Recompute & Fresh Value Retrieval:
    • Verifying that functions decorated with @cached and @cache.cached_adjacency recompute and return fresh results after cache invalidation rather than serving stale results.
  5. Capacity & LRU Eviction:
    • Verifying least-recently-used item eviction when cache capacity is exceeded.

Improvements Made

  • Added clear() method to GraphComputationCache for explicit global purges and statistics reset.
  • Aligned get_graph_cache() to cleanly delegate to the GraphComputationCache singleton, preventing stale instance references during top-level invalidate_graph_cache() invocations.

Verification

  • pytest tests/test_cache_invalidation.py passes (15/15).
  • pytest tests/test_optimization_issues_765_766_767_768.py -k "TestGraphComputationCache" passes (12/12).
  • ruff check and black --check pass cleanly with zero warnings or errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for cache invalidation in astroml/cache

2 participants