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

memcache-client-memoizer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memcache-client-memoizer

Memoizes promise-returning functions via memcache-client

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

memcache-client-memoizer

A function memoizer using memcache-client.

travis npm

Install:

npm i memcache-client-memoizer

API

memoizer(options)

Arguments

  • options: object. Required. An object with the following keys:
    • client: memcache-client instance. Required. A memcache-client instance.
    • fn: Function. Required. The function to memoize, must return a Promise.
    • keyFn: (args to fn) => 'key-string'. Required. A function which returns a string cache-key for memcached. This function is called with the same arguments as fn, allowing you to create a dynamic cache-key, for example:
      const exampleKeyFn = ({ name, color }) => `${name}:${color}`
      
    • setOptions: object. Optional. memcached-client command options.

Note:

Rejected promises and callbacks called with an err argument are not memoized, since that's a pretty bad idea :)

Example:

const MemcacheClient = require('memcache-client')
const memoizer = require('memcache-client-memoizer')

const client = new MemcacheClient({ server: 'localhost:11211' })
const fnToMemoize = ({ name, color }) => Promise.resolve({ name, color })

const memoizedFn = memoizer({
  client,
  fn: fnToMemoize,
  keyFn: ({ name, color }) => `${name}:${color}`
})

memoizedFn({name: 'Max', color: 'blue'})
  .then((result) => { ... })  // cache miss, fill cache, returns {name: 'Max', color: 'blue'}

// later on...
memoizedFn({name: 'Max', color: 'blue'})
  .then((result) => { ... })  // cache hit, returns {name: 'Max', color: 'blue'}

FAQs

Package last updated on 16 Feb 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

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