Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mycache

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mycache

A Cache library

  • 0.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Weekly downloads
 
Created
Source

Mycache

Build Status NPM version Dependency Status npm

Mycache is a cache library enhanced front end local cache, and provides two kinds of cache: persist cache and memory cache.

The persist cache use two park to store, localStorage is responsible for store the meta info, and indexeddb is responsible for store value.

Installation

NPM is the easiest and fastest way to get started using Mycache.

# latest stable
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', // name prefix of key
});

MemCache API:

// get value of key
function get(key: string): Promise<any> {}
// get all value of keys
function gets() : Promise<any> {}
// set key value and expire time
function set<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
// append key value and expire time
function append<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
// if the key has in local
function has(key: string): Promise<boolean> {}
// remove key
function remove(key: string): Promise<void> {}
// get all keys
function keys(): Promise<string[]> {}
// clear all keys
function clear(): Promise<void> {}
// the length of all keys
function length(): Promise<number> {}
// each all keys by callback
function each(iterator: (value: any, key: string, iterationNumber: number) => void): Promise<boolean> {}
// if the key is expired
function isExpired(key: string): Promise<boolean> {}

Persist Config:

import { Persist } from 'mycache';

const persist = new Persist({
  name: 'mycache', // name prefix of key
  storeName: 'persist', // The name of the datastore
  isCompress: false, // if enable string compress
  valueMaxLength: 20 * 1000, // max length of value
  oldItemsCount: 0.2, // this count of old items
});

Persist API:

// get value of key
function get(key: string): Promise<any> {}
// get all value of keys
function gets() : Promise<any> {}
// set key value and expire time
function set<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
// append key value and expire time
function append<T>(key: string, value: T, expire: number | Date = -1): Promise<T> {}
// if the key has in local
function has(key: string): Promise<boolean> {}
// remove key
function remove(key: string): Promise<void> {}
// get all keys
function keys(): Promise<string[]> {}
// clear all keys
function clear(): Promise<void> {}
// the length of all keys
function length(): Promise<number> {}
// each all keys by callback
function each(iterator: (value: any, key: string, iterationNumber: number) => void): Promise<boolean> {}
// if the key is expired
function isExpired(key: string): Promise<boolean> {}
// get all expired keys
function getExpiredKeys(): Promise<string[]> {}
// if the key is overlength
function isOverLength(key: string): Promise<boolean> {}
// get all overlength keys
function getOverLengthKeys(): Promise<string[]> {}
// if the key is old
function getOldKeys(): Promise<string[]> {}
// get items by sorted
function getSortedItems(): Promise<typed.IPersistMetaDataMap[]> {}

License

MIT

Keywords

FAQs

Package last updated on 21 Jun 2018

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