memo-storage
Storage based cache service
API
configure(options: ConfigureOptions): void
- set initial options for the instancems(parameters: Parameters): Result
- memo storage instance
Types
type Parameters {
method: Function;
params?: Array<any>;
key?: string;
expire?: number;
invalidate?: boolean;
}
type ConfigureOptions = {
logger?: Function;
onSave?: (key: string, value: any) => any;
onReceive?: (key: string) => any;
onInvalidate?: (key: string) => any;
responseParser?: (response: any) => any;
};
type Result {
data: any;
expire: number;
}
Quick start
npm install memo-storage
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: {},
};
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);
foo(1).then(console.log);