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

Adding an IndexedDB Storage #669

Closed
lucajung opened this issue Sep 5, 2023 · 7 comments
Closed

Adding an IndexedDB Storage #669

lucajung opened this issue Sep 5, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@lucajung
Copy link

lucajung commented Sep 5, 2023

Caching huge files which exceed the localstorage (5-10MB) are currently not cacheable.
IndexedDB might be the only solution to cache those responses in modern Web browsers.

@arthurfiorette
Copy link
Owner

arthurfiorette commented Sep 5, 2023

Hey! This would be an awesome feature! Up to a PR?

Reference for implementation

@arthurfiorette arthurfiorette self-assigned this Sep 5, 2023
@arthurfiorette arthurfiorette added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Sep 5, 2023
@arthurfiorette arthurfiorette pinned this issue Sep 5, 2023
@lucajung lucajung changed the title Adding a IndexedDB Storage Adding an IndexedDB Storage Sep 5, 2023
@arthurfiorette
Copy link
Owner

My only limitation here is to only merge PRs passing CI with added unit tests, anything else should be fine :)

@lucajung
Copy link
Author

lucajung commented Sep 5, 2023

With pleasure. I'll do it in the next couple of days.

@lucajung
Copy link
Author

lucajung commented Sep 6, 2023

Hey! I have it up and running. But there is an issue while writing the key value pair to the database. The set method is only receiving an empty object: "{"state":"loading","previous":"empty"}"
Do you know what I am doing wrong?
@arthurfiorette

@arthurfiorette
Copy link
Owner

@lucajung Without seeing the code I cannot help with. Open a draft PR please.

@arthurfiorette arthurfiorette linked a pull request Sep 8, 2023 that will close this issue
@CatchABus
Copy link
Contributor

CatchABus commented Nov 21, 2023

Actually, it's already possible with https://www.npmjs.com/package/idb-keyval which I happen to use for a long time.
Here's my sample:

import axios from "axios";
import { buildStorage, setupCache } from "axios-cache-interceptor";
import { clear, del, get, set } from "idb-keyval";

setupCache(axios, {
  storage: buildStorage({
    async find(key) {
      let value;
      try {
        value = await get(key);
        if (value != null) {
          value = JSON.parse(value);
        }
      } catch (err) {
        log.warn(err);
      }
      return value;
    },
    async set(key, value) {
      try {
        await set(key, JSON.stringify(value));
      } catch (err) {
        log.warn(err);
      }
    },
    async remove(key) {
      try {
        await del(key);
      } catch (err) {
        log.warn(err);
      }
    }
  })
});

@arthurfiorette
Copy link
Owner

@arthurfiorette arthurfiorette unpinned this issue Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants