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

Turn off cache? #15

Closed
davej opened this issue Sep 6, 2022 · 4 comments
Closed

Turn off cache? #15

davej opened this issue Sep 6, 2022 · 4 comments

Comments

@davej
Copy link
Contributor

davej commented Sep 6, 2022

If an object in R2 is deleted then the cache still serves the old file. Even if I upload a new file at the same path then the old file is still served.

I suggest a way to either (a) opt-out of the cache completely, or (b) provide some way to manually invalidate the cache. Any ideas? Particularly ideas for (b)?

@kotx
Copy link
Owner

kotx commented Sep 6, 2022

a), in wrangler.toml:

# The `cache-control` header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control.
# Optional, the `cache-control` header is omitted if unset, which would NOT disable caching: https://developers.cloudflare.com/workers/runtime-apis/cache/#headers
# For example, you can disable all cache by setting this to `no-store`.
CACHE_CONTROL = "max-age=86400"

So just set it like CACHE_CONTROL = "no-store"

b)
You can manually invalidate the cache by going to the Cloudflare dashboard and purging the cache for URL(s) in a zone like so:
image

@davej
Copy link
Contributor Author

davej commented Sep 6, 2022

@kotx thanks! I think (b) is for the Cloudflare CDN cache and not the worker’s internal cache.

@kotx
Copy link
Owner

kotx commented Sep 6, 2022

@kotx thanks! I think (b) is for the Cloudflare CDN cache and not the worker’s internal cache.

Are you sure the cache is not shared? The Cache API that the worker uses should allow at least purging by tag, host, or prefix. Purging by URL should also work, but I'm not sure on the wording. Take a look at the documentation for details.

@davej
Copy link
Contributor Author

davej commented Sep 7, 2022

I'm not sure at all, to be honest, the docs suggested to me that they were different. If they are the same cache then they could probably be deleted programmatically using the Cloudflare API. Something like this:

await fetch(
  "https://api.cloudflare.com/client/v4/zones/aa7f1c06205063c0a3b298060d716e7f/purge_cache",
  {
    body: JSON.stringify({
      files: [pathToDelete],
    }),
    headers: {
      "Content-Type": "application/json",
      // auth headers
    },
    method: "POST",
  }
);

@kotx kotx closed this as completed in 40292fe Sep 7, 2022
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

No branches or pull requests

2 participants