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: add onlyUpdateCache option #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tw7613781
Copy link

provide an option to only update cache no matter cache be hit or missed to meet some business logic requirements.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (83df4de) 62.67% compared to head (b6d3788) 64.70%.
Report is 6 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   62.67%   64.70%   +2.02%     
==========================================
  Files           5        5              
  Lines         284      289       +5     
==========================================
+ Hits          178      187       +9     
+ Misses         93       90       -3     
+ Partials       13       12       -1     
Flag Coverage Δ
unittests 64.70% <100.00%> (+2.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chenyahui
Copy link
Owner

In your scenario, is the response not required in any case (regardless of requesting the backend or not)? Only used to refresh cache?

@tw7613781
Copy link
Author

Thank you for prompt reply.
The response is required, it should be the latest result of requesting the backend service.

The full scenario is as follow:
the http service will have 2 endpoints.

  • one endpoint cache the result (for eg: /cache/dataset?uid=1)
  • one endpoint return the latest result from backend and refresh the cache of the above endpoint (for eg: /dataset?uid=1, it will refresh the cache of /cache/dataset?uid=1)

the code is as below

r.GET("/cache/dataset", cache.CacheByRequestURI(memoryStore, time.Hour*2, cache.IgnoreQueryOrder()), handlerFunc)
r.GET("/dataset", cache.CacheByRequestURI(memoryStore, time.Hour*2, cache.OnlyUpdateCache(), cache.IgnoreQueryOrder(), cache.WithPrefixKey("/cache")), handlerFunc)

@chenyahui
Copy link
Owner

I probably understand. Let me think about this scenario first and see if there is a more suitable solution.

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.

3 participants