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

🔑 feat: Implement TTL Mgmt. for In-Memory Keyv Stores #5127

Merged
merged 1 commit into from
Dec 28, 2024

Conversation

danny-avila
Copy link
Owner

Summary

I implemented in-memory TTL management for the cache when Redis is not used, ensuring expired entries are properly cleared. Additionally, I added a DEBUG_MEMORY_CACHE environment variable to enable debugging of the memory cache.

The motivation for this was discovering that TTL was not being done for in-memory cache when using Keyv.

  • Added functions getTTLStores, clearExpiredFromCache, and clearAllExpiredFromCache to manage cache TTLs when using in-memory cache.
  • Implemented periodic cleanup intervals to clear expired cache entries every 30 seconds when Redis is not enabled.
  • Added memory usage and cache entry logging when DEBUG_MEMORY_CACHE is enabled.
  • Handled graceful shutdown by clearing intervals and performing final cleanup before process exit.
  • Adjusted cache TTLs, changing the messages cache TTL from 5 minutes to 1 minute.

Change Type

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes

This commit updates the cache stores in the `getLogStores.js` file to use Redis as the store if the `USE_REDIS` environment variable is enabled. It also adds a new environment variable `DEBUG_MEMORY_CACHE` to enable debugging of the memory cache.

Co-authored-by: Danny Avila <[email protected]>
@danny-avila danny-avila merged commit d9c59b0 into main Dec 28, 2024
2 checks passed
@danny-avila danny-avila deleted the chore/monitor-mem-usage branch December 28, 2024 22:32
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