Socket
Socket
Sign inDemoInstall

memo-storage

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    memo-storage

Storage based cache service


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

memo-storage

Storage based cache service

API

  • configure(options: ConfigureOptions): void - set initial options for the instance
  • ms(parameters: Parameters): Result - memo storage instance

Types

type Parameters {
  method: Function; // method the results of which will be cached
  params?: Array<any>; // list of method arguments
  key?: string; // default method name
  expire?: number; // time in milliseconds after which the cache will be cleared
  invalidate?: boolean; // flag to delete data from cache
}

type ConfigureOptions = {
  logger?: Function;
  onSave?: (key: string, value: any) => any; // handle on set the data in the storage
  onReceive?: (key: string) => any; // handle on receive the data from the storage
  onInvalidate?: (key: string) => any; // handle on delete the data from the storage
  responseParser?: (response: any) => any; // // process the result returned by the method from the passed parameters
};

type Result {
  data: any;
  expire: number;
}

Quick start

npm install memo-storage
// storage.js

export default {
  set: function(key, value) {
    this.data[key] = value;
  },
  get: function(key) {
    return this.data[key];
  },
  remove: function(key) {
    delete this.data[key];
  },
  data: {},
};
// example.js
import Storage from 'storage';
import ms, { configure } from 'memo-storage';

configure({
  onSave: Storage.set,
  onReceive: Storage.get,
  onInvalidate: Storage.remove,
});

const foo = params =>
  ms({
    method: v => Promise.resolve(v),
    params: [params],
    expire: 1000,
  });

foo(1).then(console.log); // { data: 1, expire: 1572288209544 } from promise
foo(1).then(console.log); // { data: 1, expire: 1572288209544 } from cache

Keywords

FAQs

Last updated on 28 Oct 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc