workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

[Miniflare] Add `Miniflare#purgeCache()` method to reset cache when required

Open Dav1dde opened this issue 3 years ago • 5 comments

Currently the cache is not reset when reloading the worker.

I have a [site] which gets cached, when I reload the worker to refresh the frontend ([site]), my old assets are still cached and won't get delivered until I restart MF or clear the cache some other way.

I think there should be an (optional) flag to allow resetting the cache on reload automatically.

Dav1dde avatar Jan 22 '22 18:01 Dav1dde

Hey! 👋 Miniflare sets the __STATIC_CONTENT_MANIFEST for Workers Sites to {} which tricks cloudflare/kv-asset-handler into disabling caching.

Are you using Rust? Could you disable caching in development builds perhaps? In JavaScript, you could do this by checking if the globalThis.MINIFLARE variable was set:

if (globalThis.MINIFLARE) {
  // ...
}

mrbbot avatar Jan 27 '22 20:01 mrbbot

Disabling caching works fine, through the commandline arg, but I would still like to develop and test the app with the cache enabled, but this is problematic when a reload does not reset the cache.

I am not using the kv-asset-handler, but I think this feature would also be useful with the kv handler.

Dav1dde avatar Jan 27 '22 21:01 Dav1dde

Hey! 👋 Thanks for raising this issue. I'm going to transfer this to workers-sdk as that's the new home for Miniflare 3, and that will make it easier for us to track this. Rather than adding this as a CLI option, it's likely we'll add this as a method to the API. This could be used to implement this behaviour programatically. 👍

mrbbot avatar Nov 07 '23 15:11 mrbbot

Relates to #4553

admah avatar Dec 11 '23 16:12 admah

any updates on this?

abielzulio avatar Jun 15 '25 07:06 abielzulio