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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): ensure LoadingOnceCache can only load once #1998

Merged

Conversation

maxbrunet
Copy link
Member

@maxbrunet maxbrunet commented Sep 9, 2023

Why?

Same as parca-dev/parca#3768

What?

馃 Generated by Copilot at 68d934c

Introduced a new cache type to prevent duplicate loading of data and improved cache interface naming in pkg/cache/loading.go.

How?

馃 Generated by Copilot at 68d934c

  • Rename Get method of LoadingLRUCacheWithTTL to getOrLoad and add a wrapper Get method to preserve original interface (link, link)
  • Add LoadingOnceCache type that embeds LoadingLRUCacheWithTTL and adds singleflight logic to coordinate concurrent requests for the same key (link)
  • Modify NewLoadingOnceCache function to return a pointer to LoadingOnceCache and initialize embedded cache and singleflight group (link)
  • Add Get method to LoadingOnceCache that overrides embedded cache's Get method and uses singleflight group to memoize and return the value of the first call for the same key (link)

Test Plan

Unit tests

@maxbrunet maxbrunet requested a review from a team as a code owner September 9, 2023 17:06
Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 馃弳 馃 馃挴

@kakkoyun kakkoyun merged commit 80d620c into parca-dev:main Sep 11, 2023
23 checks passed
@maxbrunet maxbrunet deleted the fix/cache/TestLoadingOnceCache-flakiness branch September 13, 2023 16:45
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.

None yet

2 participants