______________________________________
/\ \
/ \ \
/ \ \
/ \_____________________________________\__________________
/ / / \░░░░░░░░░░░/ /
/ / / \░░░░░░░░░/ /
/ / / \░░░░░░░/ /
\ / / \░░░░░/ /
\ / / \░░░/ /
\ / / \░/ /
\/_________________/___________________\_________________/
__ ______ ______ _____ ______ ______
/\ \ /\ __ \ /\ == \ /\ __-. /\ ___\ /\ == \
\ \ \____ \ \ __ \ \ \ __< \ \ \/\ \ \ \ __\ \ \ __<
\ \_____\ \ \_\ \_\ \ \_\ \_\ \ \____- \ \_____\ \ \_\ \_\
\/_____/ \/_/\/_/ \/_/ /_/ \/____/ \/_____/ \/_/ /_/
Straightforward, in browser cache using local storage
Bower
Bower install larder
NPM
npm i larder
Larder supports a simple usage of the Bowser's local storage with expirations (60 minutes by default). The library uses a configurable namespace (id) to protect and avoid clashes with items stored by other applications.
To change these values, use the defaults
method,
Larder.defaults({
id:'namespace',
expires: '120' /* two hours expiration per item */
})
The library provides all you expect from such a utility including,
save, this method expects key
, value
, and optional expires
parameter (overrides the global settings).
Larder.save('don', {
name: 'Don Juan',
height: '165cm',
weight: '59kg',
age: 66
})
fetch, retrieves the value
or a stored item - providing a key
, or it returns null
if it does not exist or has expired. All expired items are removed from the local storage.
Larder.fetch('don')
Console.log
output
Object {name: 'Don Juan', height: '165cm',weight: '59kg', age: 66}
remove, savely removes an item from the storage for the given key
.
Larder.remove('don')
output
Well, he wasn't here to start with.
clear, this method expects will clear all items with the given namespace
.
Larder.clear()
A Github reader library, Gitters uses Larder to implement cache.