UNPKG

@td-design/rn-hooks

Version:

从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率

36 lines (32 loc) 993 B
'use strict'; var _tslib = require('../../_virtual/_tslib.js'); var cache = new Map(); var setCache = function (key, cacheTime, cachedData) { var currentCache = cache.get(key); if (currentCache === null || currentCache === void 0 ? void 0 : currentCache.timer) { clearTimeout(currentCache.timer); } var timer = undefined; if (cacheTime > -1) { // if cache out, clear it timer = setTimeout(function () { cache.delete(key); }, cacheTime); } cache.set(key, _tslib.__assign(_tslib.__assign({}, cachedData), { timer: timer })); }; var getCache = function (key) { return cache.get(key); }; var clearCache = function (key) { if (key) { var cacheKeys = Array.isArray(key) ? key : [key]; cacheKeys.forEach(function (cacheKey) { return cache.delete(cacheKey); }); } else { cache.clear(); } }; exports.clearCache = clearCache; exports.getCache = getCache; exports.setCache = setCache;