-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Issue implementing custom cache in 1.0.0-beta.9 #1324
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
Comments
Nice call @beetlebum , yet it's not an ideal solution to expose the serialization helper gracefully but we're working on it. |
May I ask what exactly the issues are? As a cache backend usually it doesn't need to be aware about the original cache keys (string or array of strings), it just need to provide a KV-like functionality. I'm curious about your scenario here, to improve the API we need to understand those use cases better. Thanks!
This is expected. The function itself isn't a key type for SWR, that function argument is used for returning an actual key. |
Thanks for your message. I'm probably missing something but let me explain what I'm trying to do. In the provider I will see keys serialised, like:
When I need to access a cached item, if available, previously I would use the exposed I use the For reference, I'm working with React Native, and trying to implement a disk backed custom cache using MMKV. |
With v1, we've updated the cache API interface, and added a new API to help you serialize keys: import { unstable_serialize } from 'swr'
unstable_serialize(key) We might polish that API in the future, as we are thinking about supporting more options here. |
I have implemented a custom cache following the examples in the documentation.
Given that the methods in the Cache interface take a string as a parameter,
get: (key: string)
for example, I assumed that the keys were being serialised before being passed into these methods.I am seeing array keys coming through into the cache keys, causing all sorts of issues.
Also, the
serialize
key method is not exported as far as I can tell.It seems like function type keys are being converted to strings before arriving at the cache.
Am I missing something or is this a bug?
Should I stop using arrays as keys in the new version?
Thanks in advance.
The text was updated successfully, but these errors were encountered: