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

objectcache

v0.2.4

Published

A library for storing objects with expiration dates in Javascript (ES6/7).

Downloads

9

Readme

ObjectCache for Javascript Build Status

A library for storing objects with expiration dates in Javascript (ES6/7).

As the library employs language features from the ECMAScript 6 specification, and proposed features from the ECMAScript 7 specification, it is neccessary to compile the source to ECMAScript 5 in order to run it in most (all) environments.

The original source is preserved in this package for inclusion in other ES6+ projects, and a seperate package by the name of objectcache-es5 is available containing a pre-compiled ES5 version suitable for use in Node applications or in browsers through Browserify.

##Overview

The main ObjectCache class is simply a proxy to the driver provided upon instantiation. In order to be a valid ObjectCache driver, a class should implement the methods get(key), getMultiple(keys), set(key, value, ttl) and setMultiple(keyValuePairs, ttl). All other implementation details are up to the driver, including the choice of storage backend.

One simple driver, ObjectStoreDriver, is bundled with ObjectCache, and provides storage in the form of a simple Javascript object kept in memory. As the cache will not persist through navigation actions, this driver is mainly suitable for Single Page Applications or where you don't mind losing your cached data when navigating away or reloading. This driver is also suitable for Node applications and will remain in memory until the process is terminated.

There is potential to write a driver that would store the cache in memory and persist to disk, in order to survive process termination. Similarly, one could implement a driver that stores cache in SessionStorage/LocalStorage in the browser.

##Install

$ npm install objectcache --save

Usage

See examples.

// Import the ObjectCache library and a basic driver for storing in memory
import { ObjectCache, ObjectStoreDriver } from 'objectcache';

// Create a new cache instance using the basic object store driver
let cache = new ObjectCache(ObjectStoreDriver);

// Store 'someValue' under the key 'someCacheKey' for 900 seconds (15 minutes)
cache.set('someCacheKey', 'someValue', 900);

// Attempt to retreive the value stored under 'someCacheKey' after 5 minutes
setTimeout(() => {
  let cached = cache.get('someCacheKey');
  console.log(cached); // 'someValue'
}, 300000);

// After 15 minutes
setTimeout(() => {
  let cached = cache.get('someCacheKey');
  console.log(cached); // null (expired)
}, 600000);