How to use the @s-ui/js/lib/hash.createHash function in @s-ui/js

To help you get started, we’ve selected a few @s-ui/js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SUI-Components / sui / packages / sui-decorators / src / decorators / cache / index.js View on Github external
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

@s-ui/js

Set of JS utilities

MIT
Latest version published 2 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages