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

Cache doesn't support the cf:{cacheKey: 'cacheKeyHere'} property of a request #37

Closed
cdloh opened this issue Sep 3, 2021 · 3 comments
Closed
Labels
behaviour mismatch Different behaviour to Workers runtime fixed-in-next Fixed in next release

Comments

@cdloh
Copy link

cdloh commented Sep 3, 2021

An undocumented, but supported, feature of the cache API is the ability to supply custom cache keys via the CF object of a request

eg

let cacheKey = new Request(request, {
        'method': request.method,
        'headers': request.headers,
        'body': (request.method == 'GET' || request.method == 'HEAD' ) ? null : request.body,
        'cf': {
            'cacheKey': getCacheKey(request),
            'reallyUseCacheKey': true,
        }
    });

We use this pretty extensively within our workers. Happy to take a punt at adding it if you're willing to support it?

I'd understand if you wouldn't want to given it's largely undocumented support.

@mrbbot
Copy link
Contributor

mrbbot commented Sep 3, 2021

Hey! 👋 This should definitely be supported. In your example, is cacheKey what you pass to the first argument of cache.put/match/delete? Also is reallyUseCacheKey a real parameter 😆? What does it do?

@cdloh
Copy link
Author

cdloh commented Sep 10, 2021

It is a real parameter. At the time that we wrote the worker it was required for the worker to respect the cacheKey however I've just deployed a new version of the worker without it to test and it appears to no longer be required.

@mrbbot mrbbot added the behaviour mismatch Different behaviour to Workers runtime label Sep 27, 2021
@mrbbot mrbbot added the fixed-in-next Fixed in next release label Oct 19, 2021
@mrbbot
Copy link
Contributor

mrbbot commented Oct 27, 2021

Hey! 👋 The first pre-release of Miniflare 2 has just been released, including support for cf.cacheKey, cf.cacheTtl and cf.cacheTtlByStatus. You can find the full changelog here and install it with npm i miniflare@next -D. Please let me know if you have any other issues, and feel free to ask questions in the #miniflare channel of the Cloudflare Workers Discord server.

@mrbbot mrbbot closed this as completed Oct 27, 2021
mrbbot added a commit that referenced this issue Sep 7, 2022
The Workers Cache API only supports the `cacheKey` property of the
`request.cf` object. Miniflare incorrectly supported `cacheTtl` and
`cacheTtlByStatus`.

Refs: #37, #248, #337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviour mismatch Different behaviour to Workers runtime fixed-in-next Fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants