matthewhudson / kash

Simple in-memory caching for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KASH πŸš€πŸŽ‰

NPM Version Code Coverage Downloads License

What? πŸ€”

Fast and simple in-memory caching. πŸŽοΈπŸ’¨

Why? 🎯

Because sometimes you need straight-forward, reliable, and low-latency caching. ⚑

Installation πŸ“¦

npm install kash

And then import it:

// using es modules
import kash from "kash";

// common.js
const kash = require("kash");

// AMD
// I've forgotten but it should work.

Or use script tags and globals.

<script src="https://unpkg.com/kash"></script>

And then grab it off the global like so:

const kash = kash.default;

Synopsis πŸ“–

setTimeout(function() {
  console.log(kash.get("foo"));
}, 101);

kash.set("foo", "bar", 100);

console.log(kash.get("foo"));

Will print the following in the console:

bar
null

API πŸ› οΈ

kash.set(key, value [, expiration ])

Set a key with a value. Set expiration to remove from cache after the specified number of milliseconds. Defaults to 2000 ms.

kash.get(key)

Retrieve the value for the specified key. Returns null if key does not exist.

kash.del(key)

Deletes a key.

kash.flush()

Removes the cache of all contents.

kash.size()

Get the number of entries in the cache.

Author

twitter/matthewgh
Matthew Hudson

About

Simple in-memory caching for JavaScript

License:MIT License


Languages

Language:JavaScript 100.0%