UNPKG

@qikdev/sdk

Version:

Promise based Javascript SDK

63 lines (45 loc) 1.5 kB
import _ from 'lodash'; import {Cache} from 'axios-extensions'; /////////////////////////////////////////////////////////////////////////////// var caches = {}; /** * @classdesc A static service that provides tools for caching api requests and other information * @alias cache * @class * @hideconstructor */ var QikCache = { /////////////////////////////////////////////////// /** * A helper function to reset all caches, useful if changing organisation or logging in or out as another user * @alias cache.reset */ reset() { _.each(caches, function(cache, key) { // console.log(`Reset ${key} cache`, cache); if(cache.clear) { cache.clear() } else if(cache.reset) { cache.reset() } }) }, /////////////////////////////////////////////////// /** * A helper function to retrieve a specific cache * @alias cache.get * @param {string} key The key for the cache you want to retrieve * @return {LRUCache} The cache store for the specified key */ get(key, options) { options = options || {max:5}; if (caches[key]) { return caches[key]; } caches[key] = new Cache(options) // console.log('Created new cache', key); return caches[key]; } } /////////////////////////////////////////////////////////////////////////////// export default QikCache;