🚀 DAY 4 OF LAUNCH WEEK:Introducing Socket Scanning for OpenVSX Extensions.Learn more
Socket
Book a DemoInstallSign in
Socket

@travetto/cache

Package Overview
Dependencies
Maintainers
1
Versions
333
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/cache

Caching functionality with decorators for declarative use.

Source
npmnpm
Version
0.3.20
Version published
Maintainers
1
Created
Source

travetto: Cache

Provides a simple wrapper around lru-cache to provide standard caching constructs.

@Cacheable is a decorator that allows caching at class methods. The decorator will rewrite the method to cache on successful results. The decorator supports synchronous as well as asynchronous methods.

  class Worker {
    
    @Cacheable({ max: 1000 })
    async calculateExpensiveResult(expression: string) {
      const value = await request(`https://google.com?q=${expression}`);
      return value;
    }
  }

The @Cacheable decorator supports certain configurations:

  • name the name of the cache space
  • dispose the function to invoke on cache eviction
  • keyFn the function used to determine the cache key, defaults to all params serialized to a string
  • max the maximum number of elements that the cache will hold before eviction
  • maxAge the longest time an element is allowed to live before eviction. Defaults to infinite.

Keywords

typescript

FAQs

Package last updated on 14 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts