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

Support asynchronous methods in ICacheStore #16

Closed
therealsujitk opened this issue Jun 18, 2024 · 6 comments
Closed

Support asynchronous methods in ICacheStore #16

therealsujitk opened this issue Jun 18, 2024 · 6 comments

Comments

@therealsujitk
Copy link

It would be great if asynchronous methods were supported in ICacheStore for when developers need to implement custom caching that cannot be called synchronously.

@fostertheweb it would be great if you could review & test this PR and merge it to this fork if you think everything looks good. Thanks!

@fostertheweb
Copy link
Owner

Sorry, I need to figure out my GitHub notifications. Could we avoid making this many changes by adding an IAsyncCacheStore?

export interface IAsyncCacheStore {
  get(key: string): Promise<string | null>;
  set(key: string, value: string): Promise<void>;
  remove(key: string): Promise<void>;
}

@therealsujitk
Copy link
Author

@fostertheweb we could create a separate IAsyncCacheStore instead of modifying the current one, but it would be pointless to be honest. The rest of the changes will have to remain the same since they still have to be awaited.

Since I made the functions in ICacheStore asynchronous, we need to await all the function calls to this, and some of those function calls weren't in async functions itself, so they had to be made asynchronous as well and so on.

If we create a separate IAsyncCacheStore, we'll need to make even more changes so typescript knows that the cache store can be either ICacheStore or IAsyncCacheStore. I feel the current modification is better as it also supports the current synchronous cache store and doesn't include any breaking changes (except maybe the asynchronous logout function as mentioned in the third point under Changes).

@fostertheweb
Copy link
Owner

Ah yeah for whatever reason I was thinking you created a fully custom caching strategy, instead of extending GenericCache. This makes sense, I'll copy the PR over here.

@fostertheweb
Copy link
Owner

Solved with #18

@fostertheweb
Copy link
Owner

@therealsujitk Version 1.3.0 published to npm

@therealsujitk
Copy link
Author

@fostertheweb Thankyou!

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

2 participants