New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lru-cache-object

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

lru-cache-object

A simple proxy that creates plain javascript objects that behave like an lru cache.

0.1.1
unpublished
Source
npm
Version published
Maintainers
1
Created
Source

Build Status License: GPL v3

lru-cache-object

A simple proxy to lru-cache that creates plain javascript objects that behave like an lru cache.

Accepts the same configuration options as lru-cache

(What is an LRU cache?)

example

basic
const lru = require('lru-cache-object');
const o = lru(/* lru-cache configurtion options */);
o.cat = 'meow';
console.log(o.cat); // ==> 'meow'

const o2 = lru(2); // init with 2 item max
o2.cat = 'meow';
o2.dog = 'woof';
o2.pig = 'oink';
console.log(Object.keys(o2)); // ==> ['pig', 'dog']

recipes

with a redux reducer

With some caveats its possible to use it as lru cache reducer

export const myReducer = (state = { items: lru(100) }, action) => {
  if (action.type === 'SOME_ACTION') {
    return {
      ...state,
      items: Object.assign(state.items, action.payload),
    }
  }
  return state;
};

caveats:

  • can not use spread operator
  • this essentially modifies the original object which is a bit of a best practice no-no
  • if you data is so large that you need this, it maybe be an indicator of a bigger architectural issue

license

GNUv3

Keywords

cache

FAQs

Package last updated on 13 Apr 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