Mycache
Mycache is a cache library enhanced front end local cache. Mycache provides two kinds of cache: persist cache and memory cache. Persist cache is used localforage.
Installation
NPM is the easiest and fastest way to get started using Mycache.
npm install mycache
How to use Mycache
Init cache
import { Persist } from 'mycache';
const persist = new Persist();
Sample example used the promise/async form:
import { Persist } from 'mycache';
const persist = new Persist();
async function persist() {
await persist.set('key', 'value');
return await persist.get('key');
}
Configuration
MemCache Config:
import { MemCache } from 'mycache';
const cache = new MemCache({
name: 'mycache',
});
MemCache API:
function get(key: string): Promise<any> {}
function gets() : Promise<any> {}
function set<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
function append<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
function has(key: string): Promise<boolean> {}
function remove(key: string): Promise<void> {}
function keys(): Promise<string[]> {}
function clear(): Promise<void> {}
function length(): Promise<number> {}
function each(iterator: (value: any, key: string, iterationNumber: number) => void): Promise<boolean> {}
function isExpired(key: string): Promise<boolean> {}
Persist Config:
import { Persist } from 'mycache';
const persist = new Persist({
name: 'mycache',
storeName: 'persist',
isCompress: false,
valueMaxLength: 500 * 1000,
oldItemsCount: 0.2,
});
Persist API:
function get(key: string): Promise<any> {}
function gets() : Promise<any> {}
function set<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
function append<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
function has(key: string): Promise<boolean> {}
function remove(key: string): Promise<void> {}
function keys(): Promise<string[]> {}
function clear(): Promise<void> {}
function length(): Promise<number> {}
function each(iterator: (value: any, key: string, iterationNumber: number) => void): Promise<boolean> {}
function isExpired(key: string): Promise<boolean> {}
function getExpiredKeys(): Promise<string[]> {}
function isOverLength(key: string): Promise<boolean> {}
function getOverLengthKeys(): Promise<string[]> {}
function getOldKeys(): Promise<string[]> {}
function getSortedItems(): Promise<typed.IPersistDataMap[]> {}
License
MIT