1.0.4 • Published 7 years ago

slcache v1.0.4

Weekly downloads
6
License
MIT
Repository
-
Last release
7 years ago

slcache

Simple LocalStorage Cache inspired heavily by the Rails.cache module.

Usage

import { get } from 'slcache'

// This is both how you get and set values from the cache. 
// This will store 'value' in the cache under the key 'cache_key', with a default
// expiry of 1h
get('cache_key', 'value') // returns 'value'

// Read from the cache
get('cache_key')

// Remove something from the cache
remove('cache_key')

// get can take a function as the second param as well, storing the return value.
get('cache_key', () => {
  // ... computations
  return ...
})

// You can modify the expiry by passing a third argument to get
let future = new Date(new Date().getTime() + 1000 * 60 * 60 * 24) // 1 Day from now

get('cache_key', 'something', { expiry: new Date(future)})

Full API

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago