• This repository has been archived on 07/Jun/2018
  • Stars
    star
    930
  • Rank 49,124 (Top 1.0 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 12 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript caching framework for client side caching in the browser using localStorage - gracefully degrades when the browser doesn't support localStorage.

locache

JavaScript framework for client side caching in the browser using DOM Storage with expiring values. With a memcache inspired API usage is very simple. Locache has no dependencies and is very small.

locache gracefully degrades when the browser doesn't support localStorage. Usually this will be IE6 or IE7, you wont get any errors, but caching attempts will be silently dropped and lookups will always appear to be a cache miss.

When and why?

Locache.js isn't a replacement for cache headers, and won't replace real server side caching. However, locache can be used to help speed up pages By caching results from APIs that you can't control or by caching complex structures created in JavaScript to avoid recreating. This works well with Models in backbone or rendered templates for example.

Setting, getting and removing values

Values can be stored one at a time as shown below, these values will never expire and will only be removed when you (or the browser) removes them.

locache.set("my_key", "my_value")

locache.get("my_key")
// my_value

locache.remove("my_key")

When you store an object, that's what you'll get back. For example, a number:

locache.set("counter", 1)
typeof locache.get("counter")
// number

Storing complex objects isn't a problem too. Just make sure they are JSON serializable.

locache.set('user', {
    'name': "Dougal Matthews",
    'alias': d0ugal
})

var result = locache.get('user')

//{
//    'name': "Dougal Matthews",
//    'alias': d0ugal
//}

You can also perform batch operations.

locache.setMany({
    'name': 'locache',
    'language': 'JavaScript'
})

locache.getMany(['name', 'language'])
// ['locache', 'JavaScript']

locache.removeMany(['name', 'language'])

Setting values that expire

seconds = 5;
locache.set("key", "value", seconds);

// After 5 seconds this will return null.
locache.get("key");

Incrementing and decrementing? Sure.

locache.incr("counter")
// 1
locache.incr("counter")
// 2
locache.decr("counter")
// 1
locache.decr("counter")
// 0
locache.decr("counter")
// -1

Flushing the cache

Use the following to clear only the locache values stored in localStorage.

locache.flush()

Performing cleanup

Since localStorage doesn't support expiring values, they will still be left around. This may or may not be a problem for you. If you want to make sure they are cleaned up, use the following method on page load, or with a setTimeout loop.

locache.cleanup()

More Repositories

1

retrace

Configurable method retrying for Pythonistas.
Python
69
star
2

django-urlmiddleware

This app allows you to define middleware in your Django project based on url configurations rather than adding middleware globally to every single request.
Python
40
star
3

hassio-dropbox-upload

Hass.io Dropbox Uploader
Python
39
star
4

RstPreview

RstPreview - a SublimeText plugin to view RST files in your browser.
Python
22
star
5

pynd

Search Python Abstract Tree
Python
21
star
6

chef_recipes

Chef Recipies -- For working with Vagrant. Mostly out of date.
Ruby
14
star
7

django-consent

A Django app for managing permissions that a user has granted the website to do. This could be used for a number of requests, from asking the user if you can post to their twitter, or send them newsletter updates.
Python
12
star
8

znc_mailer

A simple plugin for ZNC that sends emails to the user when they are mentioned and not connected.
C++
9
star
9

peps

A better way to view PEPs (Python Enhancement Proposals)
CSS
9
star
10

django-appregister

Django App Register - A Django app that provides the building blocks for an app registry system (similar to the django admin registry system for classes).
Python
9
star
11

python-rfxcom

A Python 3.3+ library for working with your RFXTrx and automating your home.
Python
8
star
12

dm

DougalMatthews.com - The code for my website.
CSS
7
star
13

html5video

An app to help create HTML5 video files.
Python
5
star
14

home

Just another home automation project.
JavaScript
5
star
15

rawr

Python network utility for Growl
Python
5
star
16

metareview

Tools to download and analyse data from Code Review tools
Python
4
star
17

dotfiles

Python
4
star
18

mkdocs-versioned

Python
4
star
19

pypit

Work in progress. Analytics and testing of pypi packages.
JavaScript
4
star
20

mistral-ansible-actions

Mistral Actions for calling Ansible
Python
4
star
21

tripleo-util

Shell
3
star
22

instrap

Bootstrapping a Instack development environment.
Python
3
star
23

jsonpoint

Work in progress implementation of http://tools.ietf.org/html/rfc6901
Python
3
star
24

discode-server

Simple and quick code review
Python
2
star
25

django-formadmin

Python
1
star
26

k6-demo

JavaScript
1
star
27

hassio-snapshot-manager

Python
1
star
28

shack

Ansible for setting up my dev workstation
Python
1
star
29

jsontidy

The simplest JSON command line utility possible. Pipe JSON output from other commands to make it readable.
Python
1
star
30

discode-client-old

Python
1
star
31

mistral-lint

Python
1
star
32

rfxtrx2mqtt

Python
1
star