question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Invalidation callback

See original GitHub issue

Similar to axios-cache-adapter callback called invalidate.

With this callback, we could easily fine-tune the interceptor’s behaviour, by inspecting the current request id, method and what not.

As an example, this is what I have right now, along with axios-cache-adapter:

async function invalidate (config, req) {
  if (req.forceRefresh) {
    await invalidateByForcedRefresh(config, req)
  } else if (req.method.toLowerCase() !== 'get') {
    await invalidateByMethod(config, req)
  }
}

It allows me to pass in extra arguments (like forceRefresh in this case) straight from each request, allows me to test for id patterns for clearing cache, etc.

The reason is that the current update[id] method can be a little too simplistic. I may have an user requesting GET /things?filter=alpha and GET /things?filter=beta, and I want both cached. When the user does POST /thing, I want to invalidate both entries with different filters. Currently, I would have to implement that into each request point, making sure I generate suitable IDs and clearing all caches after a success.

The callback would allow me to better defined default invalidation behaviour into a centralised place.

Edit:

Another common case is multiple page loading. GET /things and GET /things?nextPageToken=ABCDE are both parts of the same query, and both need to be invalidated if a new item is added.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
arthurfiorettecommented, Jul 29, 2022

@nolde, just released v0.10.7, can you test it out?

1reaction
arthurfiorettecommented, Jul 28, 2022

@nolde, i got time and created a PR with the above changes. Can you take a look at it before I merge into prod?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom cache invalidation callback - LVGL Forum
The STM32 DMA2D driver currently has a static function within it that invalidates the D-Cache. This is not usable out-of-the-box with an ...
Read more >
Feature Request: Expose Cancelled Batch Status to Callbacks ...
This is a feature request following up on the discussion in issue #3321 . ... Indicates if one or more jobs in batch...
Read more >
Custom Cache Invalidation - Cloudinary Support
Custom cache invalidation feature is available for customers on Enterprise / Custom Plans. This article applies to customers whose CDNs...
Read more >
Automated Re-fetching | Redux Toolkit
If a mutation is fired which is said to invalidate tags that a query cache has provided, the cached data will be considered...
Read more >
Using requestIdleCallback - Chrome Developers
requestIdleCallback is new performance API for scheduling work when the browser is idle.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found