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

🐛 BUG: The cache field on RequestInitializerDict is not implemented in fetch #698

Open
dgraham opened this issue Apr 7, 2023 · 59 comments
Labels
feature request Request for Workers team to add a feature

Comments

@dgraham
Copy link

dgraham commented Apr 7, 2023

Which Cloudflare product(s) does this pertain to?

Workers for Platforms

What version of Wrangler are you using?

Latest

What operating system are you using?

All

Describe the Bug

Making a fetch request with the cache field throws the following exception.

The cache field on RequestInitializerDict is not implemented
const response = await fetch(url, {
  cache: 'no-store',
  method: 'POST',
  body: JSON.stringify(body),
  headers: {'Content-Type': 'application/json'}
})

This was reported in our database driver in planetscale/database-js#102. We're using the cache attribute to advise the runtime to avoid caching any responses since the response body is an SQL result set that varies on every request.

A similar issue was reported in cloudflare/workers-sdk#192, but I'm not sure what the resolution was there.

Is support for the standard Request.cache attribute planned? Ideally, we'd like to treat all JS runtimes identically and rely on the fetch interfaces to hide implementation details from the driver. Even "supporting" the attribute without throwing, but with no actual implementation, would be helpful here.

@rjvim
Copy link

rjvim commented Apr 14, 2023

@dgraham Downgrading to 1.6.0 seems to be a solution for now.

Will be watching this space and planetscale/database-js#102 for a solution which will work with latest version too, FYI.

Thanks.

@Qxxxx
Copy link

Qxxxx commented May 6, 2023

Same issue

@irvinebroque
Copy link
Collaborator

@dgraham — we're going to address this, just a matter of timing. Should know more specifics soon.

@penalosa penalosa transferred this issue from cloudflare/workers-sdk May 24, 2023
@penalosa penalosa removed this from workers-sdk May 24, 2023
@ignoramous
Copy link

Still seeing this:

✘ [ERROR]   Error: The 'cache' field on 'RequestInitializerDict' is not implemented.

Any workaround till this attr is implemented?

@Mdev303
Copy link

Mdev303 commented Jun 13, 2023

@ignoramous if ur using planetscale planetscale/database-js#102 (comment)

@satpalsr
Copy link

satpalsr commented Jun 22, 2023

I have same error with upstash redis db The 'cache' field on 'RequestInitializerDict' is not implemented. I deployed Next.js app with pages.

import { Redis } from "@upstash/redis"

const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
})


try {
      data = await redis.get(userEmail);
} catch (err) {
      return new Response(`Could not access DB ${err}`, { status: 500 })
}

@LarchLiu
Copy link

I have same error with upstash redis db The 'cache' field on 'RequestInitializerDict' is not implemented. I deployed Next.js app with pages.

import { Redis } from "@upstash/redis"

const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
})


try {
      data = await redis.get(userEmail);
} catch (err) {
      return new Response(`Could not access DB ${err}`, { status: 500 })
}

@satpalsr upstash redis should have fixed this issue @v1.20.3.
upstash/redis-js#338 (comment)

@satpalsr
Copy link

I was using @upstash/redis, it's working with @upstash/redis/cloudflare. Thanks

@trd-sys
Copy link

trd-sys commented Jul 11, 2023

Any update on this? I am still seeing

The 'cache' field on 'RequestInitializerDict' is not implemented
error when using latest @planetscale/database. Any workaround suggestions are appreciated. Thanks!

@erxclau
Copy link

erxclau commented Jul 11, 2023

@trd-sys There is a workaround in planetscale/database-js#102 (comment)

@harrytran998
Copy link

Hope this bugs will solved in features soon 😆

@OrientusPrime
Copy link

@dgraham — we're going to address this, just a matter of timing. Should know more specifics soon.

Any update?

@wjaynsley
Copy link

Adding the below to my config fixed the issue for my worker:
const config = { host: 'aws.connect.psdb.cloud', username: 'test', password: 'password', fetch: (url: any, init: any) => { delete init['cache'] return fetch(url, init) } };

The delete cache part of the config seems to fix.

@pleopardi
Copy link

The delete init["cache"] workaround is not working in my case

@ryoppippi
Copy link

I got the same issue on production w/ lucia

@Rahul-codoffer
Copy link

Trying to use the cloudflare worker with the planet scale and Drizzle ORM

Error: The 'cache' field on 'RequestInitializerDict' is not implemented.
at checkURL (file:///Users/Sites/workers/.wrangler/tmp/bundle-ttBx9L/checked-fetch.js:9:9)
at Object.fetch (file:///Users/Sites/workers/.wrangler/tmp/bundle-ttBx9L/checked-fetch.js:27:3)
at postJSON (file:///Users/Sites/workers/node_modules/@planetscale/database/dist/index.js:125:28)
at Connection.execute (file:///Users/Sites/workers/node_modules/@planetscale/database/dist/index.js:81:29)
at Client.execute (file:///Users/Sites/workers/node_modules/@planetscale/database/dist/index.js:23:34)
at PlanetScalePreparedQuery.execute (file:///Users/Sites/workers/node_modules/src/planetscale-serverless/session.ts:87:33)
at MySqlSelectBase.execute (file:///Users/Sites/workers/node_modules/src/mysql-core/query-builders/select.ts:961:25)
at MySqlSelectBase.then (file:///Users/Sites/workers/node_modules/src/query-promise.ts:31:15)

nickbabcock added a commit to pdx-tools/pdx-tools that referenced this issue Aug 3, 2024
Starting to get close to the "Fast Origin Transfer" limit on Vercel for
what I believe is the S3 proxy for save files. I don't believe it is the
bandwidth from Cloudflare (which underpins Vercel's edge runtime) to
Backblaze B2 (the S3 provider) as they are partners in the bandwidth
alliance, but rather the bandwidth from the edge runtime to the user.

Considering I'd like to keep a reverse proxy in front of S3 for the
flexibility, Vercel is starting to look limiting.

This commit changes the deployment to cloudflare pages. The following changes were needed:

- Remove `no-store` from the fetch cache as cloudflare doesn't support
  it. cloudflare/workerd#698 Makes me question
  if Vercel's edge runtime actually runs on Cloudflare. `no-store` may
  not have been critical either.
- A patch was needed for `next-on-pages` to allow our split deployment
  with latent nodejs functions to be considered valid.
- `_routes.json` is added so that only api functions are counted as
  function executions. Otherwise users accessing docs or index.html (in
  a pure SPA) is counted against the Cloudflare function limit.
nickbabcock added a commit to pdx-tools/pdx-tools that referenced this issue Aug 3, 2024
Starting to get close to the "Fast Origin Transfer" limit on Vercel for
what I believe is the S3 proxy for save files. I don't believe it is the
bandwidth from Cloudflare (which underpins Vercel's edge runtime) to
Backblaze B2 (the S3 provider) as they are partners in the bandwidth
alliance, but rather the bandwidth from the edge runtime to the user.

Considering I'd like to keep a reverse proxy in front of S3 for the
flexibility, Vercel is starting to look limiting.

This commit changes the deployment to cloudflare pages. The following changes were needed:

- Remove `no-store` from the fetch cache as cloudflare doesn't support
  it. cloudflare/workerd#698 Makes me question
  if Vercel's edge runtime actually runs on Cloudflare. `no-store` may
  not have been critical either.
- A patch was needed for `next-on-pages` to allow our split deployment
  with latent nodejs functions to be considered valid.
- `_routes.json` is added so that only api functions are counted as
  function executions. Otherwise users accessing docs or index.html (in
  a pure SPA) is counted against the Cloudflare function limit.
nickbabcock added a commit to pdx-tools/pdx-tools that referenced this issue Aug 4, 2024
Starting to get close to the "Fast Origin Transfer" limit on Vercel for
what I believe is the S3 proxy for save files. I don't believe it is the
bandwidth from Cloudflare (which underpins Vercel's edge runtime) to
Backblaze B2 (the S3 provider) as they are partners in the bandwidth
alliance, but rather the bandwidth from the edge runtime to the user.

Considering I'd like to keep a reverse proxy in front of S3 for the
flexibility, Vercel is starting to look limiting.

This commit changes the deployment to cloudflare pages. The following changes were needed:

- Remove `no-store` from the fetch cache as cloudflare doesn't support
  it. cloudflare/workerd#698 Makes me question
  if Vercel's edge runtime actually runs on Cloudflare. `no-store` may
  not have been critical either.
- A patch was needed for `next-on-pages` to allow our split deployment
  with latent nodejs functions to be considered valid.
- `_routes.json` is added so that only api functions are counted as
  function executions. Otherwise users accessing docs or index.html (in
  a pure SPA) is counted against the Cloudflare function limit.
nickbabcock added a commit to pdx-tools/pdx-tools that referenced this issue Aug 7, 2024
Starting to get close to the "Fast Origin Transfer" limit on Vercel for
what I believe is the S3 proxy for save files. I don't believe it is the
bandwidth from Cloudflare (which underpins Vercel's edge runtime) to
Backblaze B2 (the S3 provider) as they are partners in the bandwidth
alliance, but rather the bandwidth from the edge runtime to the user.

Considering I'd like to keep a reverse proxy in front of S3 for the
flexibility, Vercel is starting to look limiting.

This commit changes the deployment to cloudflare pages. The following changes were needed:

- Remove `no-store` from the fetch cache as cloudflare doesn't support
  it. cloudflare/workerd#698 Makes me question
  if Vercel's edge runtime actually runs on Cloudflare. `no-store` may
  not have been critical either.
- A patch was needed for `next-on-pages` to allow our split deployment
  with latent nodejs functions to be considered valid.
- `_routes.json` is added so that only api functions are counted as
  function executions. Otherwise users accessing docs or index.html (in
  a pure SPA) is counted against the Cloudflare function limit.
@reimertz
Copy link

reimertz commented Aug 7, 2024

we are hitting this error now too running a Next.js + Shopify integration

@ImLunaHey
Copy link

since its been a few months, @jasnell can we please get an official update on this?

nickbabcock added a commit to pdx-tools/pdx-tools that referenced this issue Aug 9, 2024
* Support cloudflare pages next.js deployment

Starting to get close to the "Fast Origin Transfer" limit on Vercel for
what I believe is the S3 proxy for save files. I don't believe it is the
bandwidth from Cloudflare (which underpins Vercel's edge runtime) to
Backblaze B2 (the S3 provider) as they are partners in the bandwidth
alliance, but rather the bandwidth from the edge runtime to the user.

Considering I'd like to keep a reverse proxy in front of S3 for the
flexibility, Vercel is starting to look limiting.

This commit changes the deployment to cloudflare pages. The following changes were needed:

- Remove `no-store` from the fetch cache as cloudflare doesn't support
  it. cloudflare/workerd#698 Makes me question
  if Vercel's edge runtime actually runs on Cloudflare. `no-store` may
  not have been critical either.
- A patch was needed for `next-on-pages` to allow our split deployment
  with latent nodejs functions to be considered valid.
- `_routes.json` is added so that only api functions are counted as
  function executions. Otherwise users accessing docs or index.html (in
  a pure SPA) is counted against the Cloudflare function limit.
DTrombett added a commit to DTrombett/ms-bot-dashboard that referenced this issue Aug 21, 2024
@AyushShivhare79
Copy link

I was using @upstash/redis, it's working with @upstash/redis/cloudflare. Thanks

This works, Thanks

@destructo570
Copy link

destructo570 commented Sep 16, 2024

Hello I am trying to upload images to s3 and ran into this problem.

`
const createDocument = async (
s3: S3Client,
file: File,
bucket: string
): Promise => {
const docId = v4();
const arrayBuffer = await file.arrayBuffer();
const fileContent = new Uint8Array(arrayBuffer);
const params = {
Body: fileContent,
Bucket: bucket,
Key: docId,
ContentType: file.type,
};

// Upload file to S3
const uploadCommand = new PutObjectCommand(params);
const response = await s3.send(uploadCommand);
return docId;
};
`

Error: The 'cache' field on 'RequestInitializerDict' is not implemented.

@aslakhellesoy
Copy link

We ran into the same problem when we tried to send a message to AWS Firehose. We fixed it with this code:

const firehoseClient = new FirehoseClient({
		region: AWS_REGION,
		credentials: {
			accessKeyId: AWS_ACCESS_KEY_ID,
			secretAccessKey: AWS_SECRET_ACCESS_KEY,
		},
		requestHandler: {
			// Cloudflare doesn't support the cache option, so we remove it.
			requestInit: () => ({
				cache: undefined,
			}),
		},
	});

The general solution is to find a configuration option that lets you disable the cache field. How this is done varies between different libraries, but I'd guess it's similar for all AWS libraries.

@destructo570
Copy link

@aslakhellesoy Thanks dude. This fixed the issue for me.

@peterhirn
Copy link

This issue started to show up when using @aws-sdk/client-ses, workaround:

const client = new SESClient({
  region: AWS_REGION,
  credentials: {
    accessKeyId: AWS_ACCESS_KEY_ID,
    secretAccessKey: AWS_SECRET_ACCESS_KEY
  },
  requestHandler: {
    requestInit() {
      return { cache: undefined };
    }
  }
});

@jcottam
Copy link

jcottam commented Sep 27, 2024

I was using @upstash/redis, it's working with @upstash/redis/cloudflare. Thanks

This did the trick for me on my Nuxt w/ Nitro server project that's hosted on Cloudflare Pages. Thank you!

@tewaro
Copy link
Contributor

tewaro commented Oct 28, 2024

Update: We expect cache: no-store to be available November 11th as the default. You can enable it using the compat flag cacheOptionEnabled. We are currently working on cache: no-cache.

Note: As pointed out by @simmbiote below the actual compat option is: cache_option_enabled.

@simmbiote
Copy link

simmbiote commented Nov 14, 2024

Update: We expect cache: no-store to be available November 11th as the default. You can enable it using the compat flag cacheOptionEnabled. We are currently working on cache: no-cache.

Hi @AdityaAtulTewari When I tried cacheOptionEnabled and deployed it failed saying "no deployment was found".
I changed it to cache_option_enabled (because nodejs_compat is also snake case), and no longer experiencing the error. Is cache_option_enabled expected to work?

@tewaro
Copy link
Contributor

tewaro commented Nov 14, 2024

Hi @AdityaAtulTewari When I tried cacheOptionEnabled and deployed it failed saying "no deployment was found". I changed it to cache_option_enabled (because nodejs_compat is also snake case), and no longer experiencing the error. Is cache_option_enabled expected to work?

Yes my apologies, my original comment should have had the snake case variant, not the camel case one.

Edit: Docs for more details https://developers.cloudflare.com/workers/configuration/compatibility-flags/#enable-cache-no-store-http-standard-api

@harrismcc
Copy link

I'm still having this issue, even with the new flags enabled. Getting the error The 'cache' field on 'RequestInitializerDict' is not implemented. Any word on this?

@tewaro
Copy link
Contributor

tewaro commented Nov 22, 2024

We still haven't rolled out support for no-cache. But you should be seeing a TypeError that says Unsupported cache mode: no-cache. If I could get any information on how to deploy this myself, I can try to identify why you are running into that. Are there some docs you can point me to?

@jasnell
Copy link
Member

jasnell commented Nov 22, 2024

You'll need to update your compatibility date to at least 2024-11-11 (when the flag became active by default) or manually set the cache_option_enabled compatibility flag in your worker. Double check both or try both. If you're still having issues, please put together a simple repro worker that demonstrates it and we'll give it a try.

@harrismcc
Copy link

harrismcc commented Nov 22, 2024

I've re-created a minimal example here: https://codesandbox.io/p/devbox/ty6x35

If I set those compatibility flags, I do now see the error Unsupported cache mode: no-cache. However my use-case is still broken since the library uses that flag. Is there a workaround for this? And/or an ETA on the rollout for compatibility?

@jasnell
Copy link
Member

jasnell commented Nov 22, 2024

There's no workaround yet other than removing that option. Now that no-store is implemented, the next step will be to get no-cache supported. No ETA on that yet beyond "as soon as possible". What makes it a bit more complicated is that the actual implementation of the no-cache semantics (and no-store for that matter) is not actually within workerd. That part is deferred to another part of our infrastructure that handles the actual cache implementation and we need to coordinate the effort with that team to make sure things work correctly. Just means it takes a bit longer to do.

@harrismcc
Copy link

Makes sense, I'll be looking forward to the change! In the meantime, I've put up a PR for the library to disable this flag so hopefully that will resolve things in the meantime. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for Workers team to add a feature
Projects
None yet
Development

No branches or pull requests