feat: add onlyUpdateCache option
provide an option to only update cache no matter cache be hit or missed to meet some business logic requirements.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
83df4de) 62.67% compared to head (b6d3788) 64.70%. Report is 6 commits behind head on main.
:exclamation: 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%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
In your scenario, is the response not required in any case (regardless of requesting the backend or not)? Only used to refresh cache?
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)
I probably understand. Let me think about this scenario first and see if there is a more suitable solution.