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

fix: Add clear method to Cache interface #1480

Closed
wants to merge 1 commit into from

Conversation

myarete
Copy link

@myarete myarete commented Sep 20, 2021

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ed57cb7:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

@shuding
Copy link
Member

shuding commented Sep 21, 2021

Thanks for the PR! clear is currently not a strong requirement for the cache provider, as we don't intend to require every method of Map to be implemented as the custom cache but only the very basic ones. I think a type-safe way to do this is:

if (cache instanceof Map) cache.clear()

@piotr-cz
Copy link

piotr-cz commented Feb 7, 2022

Anyway this method is described in Cache docs:

cache.clear() // ⚠️ Clear all the cache. SWR will revalidate upon re-render.

To maintain backward compatibility with custom Cache Provider implementations (which are not an instances of Map), I'd suggest adding the clear method` as an optional method:

export interface Cache<Data = any> {
    // ...
    clear?(): void;
}

BTW methods has been removed from interface in b38d1bd#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410aL217

@huozhi huozhi mentioned this pull request Apr 20, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants