npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ozee-cachejs

v1.0.0

Published

A cache lib based on LocalStorage and SessionStorage

Downloads

1

Readme

Cachejs

Cachejs is a javascript library that uses LocalStorage and SessionStorage for cache datas on your application.

Requirements

Web browser with LocalStorage and SessionStorage :

  • Chrome 5+
  • Firefox 3.5+
  • IE 8+
  • Safari 4+
  • Opera 10.50+
  • Safari Mobile iOS 3.2
  • Android 2.1+

Installation

With npm

With bower

Other method

Download this repository and copy files on your project (not recommended)

Quick Start

Load the lib :

<html>
	<head>
		<script src="/lib-path/cachejs/dist/cache.min.js"></script>
	</head>
</html>

Store data in local storage

Cachejs.Local.set('key', 'local');

Store data in session storage

Cachejs.Session.set('key', 'session');

Get data in local storage

Cachejs.Session.get('key'); // return 'local'

Get data in session storage

Cachejs.Session.get('key'); // return 'session'

Classes

Cachejs.Local (use localStorage)

The localStorage property allows you to access a local Storage object. localStorage is similar to sessionStorage. The only difference is that, while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the browsing session ends—that is, when the browser is closed.

Cachejs.Session (use sessionStorage)

The sessionStorage property allows you to access a session Storage object. sessionStorage is similar to Window.localStorage, the only difference is while data stored in localStorage has no expiration set, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.

Methods

Cachejs.Local and Cachejs.Session have access to the same functions.

Set

Add the key to the storage, or update that key's value if it already exists set(key, value, expiration = null, readOnly = false)

Parameters

  • {string} key : name of the key you want to create/updat
  • {mixed} value : value you want to give the key you are creating/updating (string, int, array, object...)
  • {mixed} expire : (int) the data expires in x seconds || (falsy) no expiration
  • {mixed} readOnly : (true) prohibit modification || (falsy)

Return

Boolean : (true) success || (false) fail

Exemples

  • String, int...
// String
Cachejs.Local.set('key', 'value');

// Array
Cachejs.Local.set('key', [1,2,3]);

// Object
Cachejs.Local.set('key', {fistname: 'James', lastname: 'Bond'});

// With expiration
Cachejs.Local.set('key', 'value', 3600); // data expires in 1 hour

// ReadOnly
Cachejs.Local.set('key', 'value', null, true); // return true
Cachejs.Local.set('key', 'change'); // return false
Cachejs.Local.get('key'); // return 'value'

Get

Get only value, remove if expired get(key)

Parameters

  • {string} key

Return

Mixed : the value OR null if the data has expired or not exist

Exemples

Cachejs.Local.set('key', 'value');

Cachejs.Local.get('key'); // 'value'
Cachejs.Session.get('key'); // null

Cachejs.Local.set('key', 'value', 1);
// sleep 2 secondes or more
Cachejs.Local.get('key'); // null

Remove

Remove data if don't readonly remove(key)

Parameters

  • {string} key

Return

Boolean : (true) success || (false) fail

Exemples

Cachejs.Local.set('key', 'value');
Cachejs.Local.get('key'); // 'value'
Cachejs.Local.remove('key'); // true
Cachejs.Local.get('key'); // null

// ReadOnly
Cachejs.Local.set('key', 'value', null, true);
Cachejs.Local.get('key'); // 'value'
Cachejs.Local.remove('key'); // false
Cachejs.Local.get('key'); // 'value'

Clear

Remove all datas clear()

Return

true

Exemples

Cachejs.Local.set('key', 'value');
Cachejs.Local.set('key2', 'value', null, true);

Cachejs.Local.clear(); // true

Cachejs.Local.get('key'); // null
Cachejs.Local.get('key2'); // null

isExpired

Indicates whether the value has expired isExpired(key)

Parameters

  • {string} key

Return

Boolean : (true) is expired || (false) is not expired

Exemples

// No expiration
Cachejs.Local.set('key', 'value');
Cachejs.Local.isExpired('key'); // false

// No expired
Cachejs.Local.set('key', 'value', 999999);
Cachejs.Local.isExpired('key'); // false

// Expired
Cachejs.Local.set('key', 'value', 1);
// sleep 1 second or more
Cachejs.Local.isExpired('key'); // true

isReadonly

Indicates whether the value is readonly isReadonly(key)

Parameters

  • {string} key

Return

Boolean : (true) is read only || (false) is not read only

Exemples

// No readonly
Cachejs.Local.set('key', 'value');
Cachejs.Local.isReadonly('key'); // false

// is readonly
Cachejs.Local.set('key', 'value', null, true);
Cachejs.Local.isReadonly('key'); // true