1.1.0 • Published 5 years ago

klache v1.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Klache

JavaScript Style Guide

Klache is a simple javascript localStorage wrapper with cache expiry built-in and hey, you use it in the browser.

Contents

Installation

npm install klache

Getting Started

Include the script from the /dist directory

<script src="dist/klache.min.js"></script>

or use klache as a UMD and bundle it using Webpack.

var klache = require('klache')

Example

var cache = {key:'myStorageKey', expires:60};
var data = klache.get(cache.key);
if (!data){
  // fetch new data or do something...
  var data = {foo:'bar'};
  // create a local storage object that expires in 60 seconds...
  klache.set(cache.key, data, cache.expires);
  console.log('Saved to localStorage:', data);
} else {
  console.log('Retrieved from localStorage:', data);
}

API

klache.removeAll()

Delete all local storage objects.

Example

klache.removeAll();

klache.removeKey(string $key)

Delete a local storage object by key.

paramtypedescription
$keystringthe local storage object key to remove.

Example

klache.removeKey('myKey');

klache.get(string $key)

Get a local storage object by key.

paramtypedescription
$keystringthe local storage object key to retrieve.

Example

var data = klache.get('myStorageKey');

klache.set(string $key, object $payload, int $expiryInSeconds)

Create or update a local storage object by key.

paramtypedescription
$keystringthe local storage object key.
$payloadobjectthe object to store.
$expiryInSecondsintthe expiry time in seconds.

Example

// create a local storage object that expires in 60 seconds...
klache.set('myStorageKey', {foo:'bar'}, 60);

Tests

See /tests directory for basic distribution and Webpack bundle tests.

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago