UNPKG

with-simple-caching

Version:

A wrapper that makes it simple to add caching to any function

24 lines (23 loc) 717 B
import { UniDuration } from '@ehmpathy/uni-time'; /** * a simple cache which synchronously gets and sets values to its store */ export interface SimpleSyncCache<T> { get: (key: string) => T | undefined; set: (key: string, value: T | undefined, options?: { expiration?: UniDuration | null; }) => void; } /** * a simple cache which asynchronously gets and sets values to its store */ export interface SimpleAsyncCache<T> { get: (key: string) => Promise<T | undefined>; set: (key: string, value: T | undefined, options?: { expiration?: UniDuration | null; }) => Promise<void>; } /** * a simple cache */ export type SimpleCache<T> = SimpleAsyncCache<T> | SimpleSyncCache<T>;