UNPKG

vue-condition-watcher

Version:

Vue composition API for automatic data fetching. With conditions as the core. Easily control and sync to URL query string by conditions

14 lines (13 loc) 597 B
import { serializeFunc, sortObject, stringifyQuery } from '../utils/common'; export function useCache(fetcher, provider) { const baseKey = serializeFunc(fetcher); function formatString(key) { return `${baseKey}@${stringifyQuery(sortObject(key))}`; } return { set: (key, value) => provider.set(formatString(key), value), get: (key) => (provider.get(formatString(key)) ? provider.get(formatString(key)) : undefined), delete: (key) => provider.delete(formatString(key)), cached: (key) => provider.get(formatString(key)) !== undefined, }; }