Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/cache

Package Overview
Dependencies
Maintainers
1
Versions
324
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.

  • 0.5.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39
increased by387.5%
Maintainers
1
Weekly downloads
 
Created
Source

travetto: Cache

Install: primary

$ npm install @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.

Code: Using decorators to cache expensive async call

  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

FAQs

Package last updated on 23 Jan 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc