GithubHelp home page GithubHelp logo

kizzy's Introduction

Kizzy - a Local Storage Utility

Kizzy is a light-weight, cross-browser, JavaScript local storage utility. It leverages the HTML5 localStorage API when available, as well as Internet Explorer's persistent XML store โ€” wrapped up in a easy to use, memcached-like interface. When neither of these features are available (unlikely), it falls back to an in-browser object store.

It looks like this

var cache = kizzy('users')
var agent = cache.get('Agent')
if (agent) {
  alert('Welcome back ' + agent.name)
} else {
  cache.set('Agent', {
    name: 'Agent Diaz'
  })
}

Furthermore, a call to 'set' will return the value, making it quite easy for assignment.

var cache = kizzy('users')
var agent = cache.get('Agent') || cache.set('Agent', {
  name: 'Agent Diaz'
})

Lastly, you can pass an optional third argument to 'set' that tells the cache how long to live

var cache = kizzy('users')

var agent = cache.get('Agent') || cache.set('Agent', {
  name: 'Agent Diaz'
}, 5000) // time to live set for 5 seconds


// wait 3 seconds...
setTimeout(function() {
  alert('Still there ' + cache.get('Agent').name)
}, 3000)

// 6 seconds later...
setTimeout(function() {
  cache.get('Agent').name // => expired
}, 6000)

Browser support

  • Internet Explorer 6+
  • Firefox 2+ (when localStorage is enabled (the browser default))
  • Chrome
  • Safari 4+
  • Opera

Building Kizzy

$ submodule update --init
& make

Running tests

Tests will not currently pass if run on a file:/// protocol. Otherwise...

$ open tests/test.html

Ender integration

Install Kizzy as an Ender module

$ ender add kizzy

Use it as such:

$.cache('user').get('name')

Kizzy whu?

The name comes from Kunta Kinte, a Mandinka African warrior from the 1700's. After being brought into slavery, he had a daughter whom he named Kizzy, which translates to stay put in hopes that the family would stay together, but not stay a slave.

Happy Caching!

kizzy's People

Contributors

ded avatar paulredmond avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.