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

Using KV for listing directories #159

Open
flakey5 opened this issue Nov 1, 2024 · 1 comment
Open

Using KV for listing directories #159

flakey5 opened this issue Nov 1, 2024 · 1 comment

Comments

@flakey5
Copy link
Member

flakey5 commented Nov 1, 2024

I think it's worth a shot trying out Cloudflare KV for directory listings in an effort to lower uncached response times.

How it could work

The R2Provider's listDirectory works by just rewriting to the S3Provider (src). I think we can add a KVProvider that just serves directory listings, similar to the S3Provider, and just use it there instead.

I do think we should keep the S3Provider just for extra redundancy in case there's some issue with KV or the KV provider.

The data in KV

The key would be the directory's path in R2 (i.e. nodejs/release/v20.0.0).

The value would be a stringified JSON array with the directory's contents (i.e. ['docs/', 'node.exe']).

How we get the directory listings into KV

Option A

Upon release promotion, purge the KV namespace. Then, list the entire bucket directory by directory and add them to the KV namespace. If a directory isn't present in KV, treat it like it doesn't exist and send a 404. We might be able to figure out something smart to only purge the effected directories, but it's not necessary.

Option B

Use KV like a cache. We'll check if a path exists in KV, if it doesn't then we'll fall back to the S3 provider and add the result to the KV namespace. We will need to invalidate all of the paths upon a new release getting promoted (again, we might be able to figure out something smart to only purge the effected directories).

(I would prefer option A since it also works for unknown directories and it's implementation should be simpler).

Pricing

Reference: https://developers.cloudflare.com/kv/platform/pricing/

I'm not sure how much space this would take up (I made some rough estimations of ~5mb in an earlier issue, can't seem to find it however and it was a different structure).

We would probably exceed the limit of 10 million reads free reads a month, however.

@flakey5
Copy link
Member Author

flakey5 commented Nov 1, 2024

Noteworthy that we're still caching pretty aggressively, and this will only help uncached responses.

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

1 participant