All Projects → fwh1990 → cache-bucket

fwh1990 / cache-bucket

Licence: MIT license
Light Cache for nodeJs and browserJs with TTL.

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to cache-bucket

mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+435.71%)
Mutual labels:  localstorage, sessionstorage
Nuxt Storage
🛢 Utilities for easy read and write browser's storage in Nuxt.js project
Stars: ✭ 98 (+600%)
Mutual labels:  localstorage, sessionstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (+371.43%)
Mutual labels:  localstorage, sessionstorage
Web Storage Cache
对localStorage 和sessionStorage 进行了扩展,添加了超时时间,序列化方法
Stars: ✭ 582 (+4057.14%)
Mutual labels:  localstorage, sessionstorage
React Local Storage
Showcase on how to use the native localStorage of the browser in React.
Stars: ✭ 168 (+1100%)
Mutual labels:  localstorage, sessionstorage
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (+14.29%)
Mutual labels:  localstorage, sessionstorage
Vue Mail List
vue全家桶+localStorage实现一个简易的通讯录
Stars: ✭ 81 (+478.57%)
Mutual labels:  localstorage, sessionstorage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+21057.14%)
Mutual labels:  localstorage, sessionstorage
Ngx Store
Angular decorators to automagically keep variables in HTML5 LocalStorage, SessionStorage, cookies; injectable services for managing and listening to data changes and a bit more.
Stars: ✭ 152 (+985.71%)
Mutual labels:  localstorage, sessionstorage
React Storage Hooks
React hooks for persistent state
Stars: ✭ 146 (+942.86%)
Mutual labels:  localstorage, sessionstorage
Vue Ls
💥 Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (+3242.86%)
Mutual labels:  localstorage, sessionstorage
Awesome Web Storage
😎 Everything you need to know about Client-side Storage.
Stars: ✭ 227 (+1521.43%)
Mutual labels:  localstorage, sessionstorage
Ng2 Webstorage
Localstorage and sessionstorage manager - Angular service
Stars: ✭ 395 (+2721.43%)
Mutual labels:  localstorage, sessionstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-28.57%)
Mutual labels:  localstorage, sessionstorage
Angular Locker
🗄️ A simple & configurable abstraction for local/session storage in angular js projects
Stars: ✭ 318 (+2171.43%)
Mutual labels:  localstorage, sessionstorage
Bin
A tiny (<1kb) localStorage and sessionStorage helper library.
Stars: ✭ 70 (+400%)
Mutual labels:  localstorage, sessionstorage
vue-web-storage
Vue.js plugin for local storage and session storage (1.8 kb min+gz) 💾
Stars: ✭ 85 (+507.14%)
Mutual labels:  localstorage, sessionstorage
svelte-persistent-store
A Svelte store that keep its value through pages and reloads
Stars: ✭ 111 (+692.86%)
Mutual labels:  localstorage, sessionstorage
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+11657.14%)
Mutual labels:  localstorage, sessionstorage
Brownies
🍫 Tastier cookies, local, session, and db storage in a tiny package. Includes subscribe() events for changes.
Stars: ✭ 2,386 (+16942.86%)
Mutual labels:  localstorage, sessionstorage

Introduction

Cache your data with TTL. Using this package in node.js and browser.

Installation

By npm

npm install cache-bucket

Or by yarn

yarn add cache-bucket

Support

Node.js

FileCache and MemoryCache is enable.

Notice that CacheFile will touch a file as storage. The default file path is: ./.filecache

// Based on file
import {cache} from 'cache-bucket/file-cache';

// Based on memory
import {cache} from 'cache-bucket/memory-cache';

Browser

LocalCache and SessionCache and MemoryCache is enable.

Notice that LocalCache is based on localStorage, and SessionCache is based on sessionStorage.

// Based on memory
import {cache} from 'cache-bucket/memory-cache';

// Based on localStorage
import {cache} from 'cache-bucket/local-cache';

// Based on sessionStorage
import {cache} from 'cache-bucket/session-cache';

Methods

get(key: string, defaultValue?: any) => any

Get your cache by key.

If cache is empty, defaultValue will be used. If parameter defaultValue is missing, method will respond null.

cache.get('foo'); // null
cache.get('foo', 'default-bar'); // default-bar

set(key: string, value: any, duration?: number) => void

Set cache data.

The parameter value type can be string, number, object, array. Cache data will expired after millSeconds when you provide duration.

cache.set('foo', 'bar');
cache.set('obj', {pkg: 'cache-bucket'});

// Expired after 3 second.
cache.set('array', ['cache', 'bucket'], 3000);

getOrSet(key: string, onEmpty: () => any, duration?: number) => any

Get cache data.

When cache data is missing, method will set data immediately. And then return it.

cache.getOrSet('foo', () => {
  return 'bar';
}); // bar

add(key: string, value: any, duration?: number) => boolean

Set cache data when key is not exist.

cache.add('foo', 'bar'); // true
cache.add('foo', 'new-bar'); // false

remove(key: string) => void

Delete a cache data.

cache.remove('foo');

clearExpired() => void

Clear all expired cache data

cache.clearExpired();

clearAll() => void

Clear all data.

cache.clearAll();

Advanced

Multiply instances.

import {MemoryCache} from 'cache-bucket/memory-cache';

const cache = new MemoryCache();

cache.set('foo', 'bar');
cache.get('foo'); // bar
import {FileCache} from 'cache-bucket/file-cache';

const cache = new FileCache('./.new-cachefile');

cache.set('foo', 'bar');
cache.get('foo'); // bar

Config

You can choose the file you want to put data when Using FileCache. Just creating config file cache-bucekt.json in project's root directory.

{
  "defaultFilePath": "./.custom-cache-file"
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].