Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (...args) => {
if (
(typeof window !== 'undefined' && window.__SUI_CACHE_DISABLED__) ||
(typeof global !== 'undefined' && global.__SUI_CACHE_DISABLED__)
) {
return original.apply(instance, args)
}
const key = `${target.constructor.name}::${fnName}::${createHash(
JSON.stringify(args)
)}`
const now = Date.now()
if (cache.get(key) === undefined) {
cache.set(key, {createdAt: now, returns: original.apply(instance, args)})
}
if (isPromise(cache.get(key).returns)) {
cache.get(key).returns.catch(() => cache.del(key))
}
if (now - cache.get(key).createdAt > ttl) {
cache.del(key)
}
return cache.get(key) !== undefined