Skip to content

Commit

Permalink
feat: add ttl argument in wrap method
Browse files Browse the repository at this point in the history
  • Loading branch information
zzau13 committed Oct 19, 2022
1 parent d119849 commit b06c1e5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/caching.ts
Expand Up @@ -74,11 +74,11 @@ export async function caching<S extends Store, T extends object = never>(
* const result = await cache.wrap('key', () => Promise.resolve(1));
*
*/
wrap: async <T>(key: string, fn: () => Promise<T>) => {
wrap: async <T>(key: string, fn: () => Promise<T>, ttl?: Ttl) => {
const value = await store.get<T>(key);
if (value === undefined) {
const result = await fn();
await store.set<T>(key, result);
await store.set<T>(key, result, ttl);
return result;
}
return value;
Expand Down

0 comments on commit b06c1e5

Please sign in to comment.