-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Back with Keyv #3
Comments
I like the idea. It would make this module very powerful. But I also want to optimize for the common case, which is just using the default |
I'm interested in this as well. What I want is to persist my cache on S3 so my cache can be easily shared between AWS lambda instances. I will have a look if we could easily add support for async storage providers like Keyv or some other custom providers. Would make it really nice! Will probably do it this week as I really need it :). |
@SamVerschueren There is a community adapter for Dynamo DB: https://github.com/e0ipso/keyv-dynamodb Should be faster than S3 and be accessible from AWS Lambda. I haven't had the time to look into it too much but might be useful for you. |
So, I tried building a redis cache adaptor for Maybe I'm missing something but it seems to me like this isn't a huge task, it's just that the Cache object being passed in the options doesn't get awaited on any of the IO methods (get, set, has, etc.) That also probably means you can't really use
I did a quick push so I can show you what I'm doing: https://github.com/ClaudiuCeia/p-memoize-redis/tree/master/src. It's TypeScript but I can transpile to JS and publish on npm so it can be used just as a drop-in for the |
Correct. Luckily |
What's the action on this issue? This?
|
@bfred-it Yes |
I'm not entirely sure what the problem currently is. The supplied map has to return a |
@bfred-it I haven't looked into it. You might be right. |
I tested this; for this to work, we have to if (cache.has(key)) { // if (promise)
return maxAge ? cache.get(key).data : cache.get(key); // promise.data === undefined
} |
I just stumbled upon this, when I wanted to use mem with an async cache backend based on idb-keyval. It makes sense to implement this in p-memoize instead of mem, but I think it would make a very powerful addition, since we’d be able to use basically any browser-based storage option. Right now I have to fallback to sync localStorage which really is a pity. So: all the thumbs up for supporting async caches! :) |
Now that sindresorhus/memoize#43 is in and PR welcome on
|
Is this feature working? From the code is not completely clear for me... I see the cache option is passed directly to the underlying |
@Zikoel you're right, at this moment https://github.com/sindresorhus/mem/blob/main/index.ts#L117 If you need to memoize working with |
@Kikobeats Don't link to specific lines like that, if a new commit changes anything your link will become confusing. Get a permalink instead, like this: https://github.com/sindresorhus/mem/blob/a42d7205cc7939e1738eda2a785fe1ec5bda2760/index.ts#L117 |
Since p-memoize is asynchronous, what should it do when it is called twice in a row? Should it treat both as a single call or if not, should the functions just race to be the first to cache a value? |
@sindresorhus How do you think this should be handled? |
I think it should coalesce, so the second call just receives the same promise as the first call. |
just in case you are interested, we forked keyv to keyv.js.org to keep it running and maintained since the original project is stuck 👍 |
Hmm, so for now, we just stick to synchronous caches like quick-lru only? |
Yes |
Plan: Copy This system is required because it is not possible to cache the Promise object in a database and as such, these things can not be cached between executions:
There are 3 solutions I can think of:
For users that still want the previous behaviour, should we add a seperate function for that or just remove this functionality? Also, what should the promise cache option be called, |
If the following events happen, what should
Should the second function return the cached promise or the cached value? They can't be raced against each other because the promise cache is synchronous. Right now, the promise cache will be checked first then the value cache. Also keep in mind that promise rejections can't entirely be cached across instances. |
Because different cache providers have different ways in configuring cache expiry, setting For now, I've removed that option since the |
Other calls may run into a local race condition where once Also, should |
Fixes sindresorhus#3, Fixes sindresorhus#14 Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Redirected here from
mem
sindresorhus/memoize#15 (comment)The text was updated successfully, but these errors were encountered: