Skip to content

Conversation

@27Bslash6
Copy link
Contributor

Summary

Fixes #3

When using @cache(backend=None) for L1-only caching, the decorator was still attempting to connect to Redis on every operation.

Root Cause

Sentinel problem - couldn't distinguish explicit backend=None from unspecified backend.

Changes

  • Track explicit backend=None intent via _l1_only_mode flag in intent.py
  • Skip backend provider lookup in L1-only mode in wrapper.py
  • Fix invalidate_cache() and ainvalidate_cache() to honor L1-only mode
  • Add DEBUG log when L1-only mode ignores available Redis (helps debugging)
  • Clean up ttl or ttl copy-paste cruft (8 instances)

Test Plan

  • New tests in tests/unit/test_l1_only_mode.py (10 tests)
  • Tests for sync and async L1-only mode
  • Tests for invalidate_cache() in L1-only mode
  • Tests verify backend provider is never called
  • All existing tests pass

Files Changed

  • src/cachekit/decorators/intent.py - Track explicit L1-only intent
  • src/cachekit/decorators/wrapper.py - Honor L1-only flag, add DEBUG log
  • tests/unit/test_l1_only_mode.py - New comprehensive test suite

When using @cache(backend=None) for L1-only caching, the decorator
was still attempting to connect to Redis on every operation.

Root cause: Sentinel problem - couldn't distinguish explicit backend=None
from unspecified backend.

Changes:
- Track explicit backend=None intent via _l1_only_mode flag
- Skip backend provider lookup in L1-only mode
- Fix invalidate_cache() to honor L1-only mode
- Add DEBUG log when L1-only mode ignores available Redis
- Clean up ttl or ttl copy-paste cruft

Closes #3
… level

Remove buggy check that treated DecoratorConfig.backend defaulting to
None as L1-only mode. Now only @cache(backend=None) triggers L1-only.

For L1-only with presets, use: @cache(backend=None, config=...)
Adds TestDefaultBackendBehavior class with 6 tests verifying that:
- @cache() without backend=None DOES call get_backend_provider()
- @cache.minimal/dev/test() presets behave correctly
- DecoratorConfig default (backend=None) != explicit backend=None
- Explicit backend instances bypass provider lookup

These regression tests protect against the bug where checking
`config.backend is None` would treat ALL decorators as L1-only
(since DecoratorConfig.backend defaults to None).
@27Bslash6 27Bslash6 force-pushed the fix/l1-only-mode-no-redis branch from 47f3b46 to 872fe23 Compare December 11, 2025 21:55
@27Bslash6 27Bslash6 merged commit 0898986 into main Dec 11, 2025
18 checks passed
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.

bug: @cache(backend=None) L1-only mode attempts Redis connection

2 participants