Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching #51

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Caching #51

wants to merge 7 commits into from

Conversation

nelsojona
Copy link

Add Enhanced Caching with Debug Support

This PR implements an improved caching mechanism for API responses with debug logging capabilities.

Changes

  • Added normalize_cache_key_args() function to standardize cache key generation
  • Implemented thread-safe caching with TTL and LRU eviction
  • Added debug logging for cache hits/misses with emoji indicators
  • Added --debug-cache CLI flag for easy debugging
  • Added documentation in src/utils/README.md

Features

  • Consistent cache key generation that handles:
    • Positional and keyword arguments
    • Nested dictionaries and lists
    • Date objects
  • Debug logging shows:
    • 💾 Cache MISS - When new data is stored
    • 🎯 Cache HIT - When cached data is retrieved
  • Thread-safe implementation for concurrent access
  • TTL-based cache expiration
  • LRU eviction when cache is full

Usage

Enable debug logging via code:

from utils.cache import set_debug
set_debug(True)

Or via CLI:

poetry run python src/main.py --ticker AAPL --debug-cache

Testing

Tested with multiple API endpoints and verified:

  • Cache hits/misses are logged correctly
  • Keys are generated consistently
  • Thread safety under concurrent access
  • TTL expiration works as expected

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.

1 participant