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

10.2.0 Cloudflare workers cache not implemented correctly #714

Open
4 tasks done
dct0 opened this issue Jul 31, 2024 · 1 comment
Open
4 tasks done

10.2.0 Cloudflare workers cache not implemented correctly #714

dct0 opened this issue Jul 31, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@dct0
Copy link

dct0 commented Jul 31, 2024

Steps to reproduce

  1. Create worker using npm create cloudflare
  2. Import youtuvei.js/cf-worker
  3. Instantiate a new innertube instance with the universal cache Innertube.create({ cache: new UniversalCache(true) }) in the fetch function before rendering the hello world
  4. npm run dev and visit the page

Failure Logs

X [ERROR] TypeError: Invalid URL: innertube_session_data

      at Cache.<anonymous>
  (file:///D:/Code/yt-event-reminder/node_modules/.pnpm/[email protected]/node_modules/youtubei.js/src/platform/cf-worker.ts:26:34)
      at Generator.next (<anonymous>)
      at fulfilled
  (file:///D:/Code/yt-event-reminder/node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.es6.mjs:118:56)

Expected behavior

Cache put and get calls work

Current behavior

It fails trying to retrieve session data from cache

Version

Default

Anything else?

The worker cache is designed to cache http responses for a given requests. The docs specify that if a string is passed, it is interpreted as a url. Therefore the key arg must be a url. It then fails trying to retrieve inntertube_session_data from cache, which isn't a url.

From the docs https://developers.cloudflare.com/workers/runtime-apis/cache/#cache:

cache.put will throw an error if:

The request passed is a method other than GET.
The response passed has a status of 206 Partial Content.
The response passed contains the header Vary: . The value of the Vary header is an asterisk (). Refer to the Cache API specification for more information.

It's might be possible to simply convert the key into a valid url, but this is not what it was designed to do (and the docs mention more limitations). A KV adapter would be more suited

Checklist

  • I am running the latest version.
  • I checked the documentation and found no answer.
  • I have searched the existing issues and made sure this is not a duplicate.
  • I have provided sufficient information.
@dct0 dct0 added the bug Something isn't working label Jul 31, 2024
@LuanRT LuanRT added the good first issue Good for newcomers label Jul 31, 2024
@twicer-is-coder
Copy link

Solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants