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

cache-deep

v1.1.0

Published

memory cache with deep clone and ttl

Downloads

3

Readme

node-cache-deep

Node.js cache library with deep clone

NPM Version Build Status Coverage Status

Installation

npm install cache-deep --save

Note: cache-deep requires Node.js version >= 6.x

Features

  1. deep clone option

Usage

  1. normal
const CacheDeep = require('cache-deep');
const cache = new CacheDeep();

cache.put('data', 123, 1000 * 60 * 20);   // put 123 to key 'data' and 20 minutes to live
let data = cache.get('data');  // data = 123
cache.del('data');

data = cache.get('data');  // data = null
cache.clear();
  1. with deep-clone option
const CacheDeep = require('cache-deep');
const cache = new CacheDeep({
    deepClone: true
});

let obj = {
  a: 1
};
cache.put('data', obj);
let data = cache.get('data').a;   // data = 1
obj.a = 2;
data = cache.get('data').a;   // data = 1

API

new CacheDeep([options])

Added in: v1.0.0

Cache constructor

Param:

  • options <Object> cache config options
    • deepClone <boolean> if true, use the lodash.deepClone to clone to cached value

Returns:

instance of cache

const CacheDeep = require('cache-deep');
const cache = new CacheDeep({
    deepClone: true
});

put(key, value, ttl)

Added in: v1.0.0

pput a value to the cache by key

Param:

  • key <string> cache key to save the value to cache
  • value <*> the value want to cached
  • ttl <number> time to live, the cache should be delete after this millisecond, if not given, keep the cache forever

Returns:

undefined

Throws:

  • TypeError when the key is not string
cache.put('data', 123, 1000 * 60 * 20);   // put 123 to key 'data' and 20 minutes to live

get(key)

Added in: v1.0.0

get a cached value by key

Param:

  • key <string> cache key to get the value

Returns:

cached value, or null if not hit

Throws:

  • TypeError when the key is not string
let data = cache.get('data');

del(key)

Added in: v1.0.0

delete a cached value by key

Param:

  • key <string> cache key to delete the cache

Returns:

undefined

Throws:

  • TypeError when the key is not string
cache.del('data');

clear()

Added in: v1.0.0

empty the cache

cache.clear();

statistics()

Added in: v1.1.0

get the cache hit rate info

Returns:

  • <Object>
    • count <number> count of get cache
    • hit <number> the number of get cache hit the right key
const stat = cache.statistics();
const cacheHitRate = stat.hit / stat.count;

License

MIT