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

Add TimedCache for controlled cache expiration #17557

Merged
merged 6 commits into from May 15, 2024

Conversation

lu-zhengda
Copy link
Contributor

What does this PR do?

This PR introduces the TimedCache class, which adds functionality for managing a cache where the entire cache expires after a set interval, and to be manually cleared.
This TimedCache is intended to be used in scenario where the check caches data for multiple check runs but wants to periodically clear the cache and re-build after sometime. It's mainly to avoid a cache to grow indefinitely.

Motivation

The TimedCache will be first used by postgres query metrics where we need to cache the pg_stat_statements as baseline and keep adding new queryid to the cache as new normalized queries appear. However, to avoid the baseline cache grow overtime, we will check if the cache is expired and rebuild the baseline periodically.

Additional Notes

The TimedCache is different from cachetools TTLCache. In TTLCache, every key has a TTL and expires independently. TimedCache has TTL on the entire cache but does not automatically clear the cache. This is to avoid losing cached values in the middle of the process. Developer should check if cache is expired at the beginning of the process and rebuild whenever needed.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Changelog entries must be created for modifications to shipped code
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Copy link

Test Results

 1 060 files   1 060 suites   6h 51m 39s ⏱️
 7 074 tests  7 005 ✅    69 💤 0 ❌
32 243 runs  26 734 ✅ 5 509 💤 0 ❌

Results for commit 1104341.

@lu-zhengda lu-zhengda marked this pull request as ready for review May 13, 2024 16:47
@lu-zhengda lu-zhengda requested a review from a team as a code owner May 13, 2024 16:47
@lu-zhengda lu-zhengda merged commit 971d081 into master May 15, 2024
235 checks passed
@lu-zhengda lu-zhengda deleted the zhengda.lu/dbm-timed-cache branch May 15, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants