Huge News!Announcing our $40M Series B led by Abstract Ventures.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

lru-cache-object

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

  • 0.1.2
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
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

FAQs

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

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