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

Allow Querying a CacheStorage #1694

Open
llacroix opened this issue Oct 4, 2023 · 0 comments
Open

Allow Querying a CacheStorage #1694

llacroix opened this issue Oct 4, 2023 · 0 comments

Comments

@llacroix
Copy link

llacroix commented Oct 4, 2023

Currently, the cache storage is mainly useful to store into a cache a response that matches somehow a request. So if you have a request already cached a very similar request can be found in the cache. It's fine but sometimes, it's just not enough to be very useful.

Currently, the only way you can query the cache storage is by fetching the keys and passing them through a custom router that would allow you to find a key that matches your criteria. The other way which might be a bit easier is to implement a custom database storage in an IndexedDB with the indexes that you need to search on.

For example, let say you had such url: /store/templates/xml/1?bundle=bundle1

Think of it like a xml template of version 1 and taking a bundle from this template called bundle1.

Basically, the query could try to find a bundle of the most recent version that is in the cache. So a search on:

"/store/template/xml/(?<version>\w+)\?bundle=(?<bundle>\w+)"

It would be nice if we could query the storage with something like a range or exact match.

cache.query(
    /\/store\/template\/xml\/(?<version>\w+)\?bundle=(?<bundle>\w+)/,
    {
      bundle: 'bundle1',
      version: new Range(0, new Date().valueOf())
    }
)

Or possibly allow a way to create indexes that can be queried.

   cache.createIndex('templates', (request) => extract_keys(request)) // ['bundle1', 1]

Then simply the index by taking a value from it using a key or range and possibly add a way to change the order in which the keys of the index are stored.

cache.index('templates').search(['bundle1']) // gets all bundle1 regardless of the version
cache.index('templates').search(['bundle1'], ['bundle1', 10]) // gets all bundle with a version less than 10.
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