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

extreme-cache

v1.0.3

Published

Extremely performant cache for production usage (1.2 million ops/s). Completely synchronous, no Promises required.

Downloads

4

Readme

🔥🛢 ExtremeCache

Maintenance MIT Licence JavaScript Style Guide

Extremely performant cache for production usage (1.2 million ops/s). Completely synchronous, no Promises required.

Built with:

  • LokiJS High-performance Datastore package
  • Native NodeJs Crypto package

Installation

npm install extreme-cache

Usage

Add this to the js file that you are using it in:

const ExtremeCache = require('extreme-cache')

Simple usage:

const ExtremeCache = require('extreme-cache')

const cache = new ExtremeCache('my-custom-cache') 

cache.set('cat-name', 'garfield')  // No expiry
cache.set('dog-name', 'odi', 60000) // Expires after 60000 milliseconds, which is 60 seconds

let cat = cache.get('cat-name')
let dog = cache.get('dog-name')

console.log(cat) // outputs the value - 'garfield'
console.log(dog) // outputs the value - 'odi'

Another example usage:

const ExtremeCache = require('extreme-cache')

const cache = new ExtremeCache('my-custom-cache') 

// ---- Insert a value with an expiry of 5.0 seconds ----
cache.set('personA', {name: 'john', age: 21}, 5000) 

// ---- Insert a value with no expiry ----
cache.set('personB', {name: 'enoch', age: 9999}) 

setTimeout(() => {
  // ---- Check cache after 3.0 seconds ----
  let value = cache.get('personA')
  console.log(value) // Returns {name: 'john', age: 21}
}, 3000)

setTimeout(() => {
  // ---- Retrieve the entire cache after 4.0 seconds ----
  let value = cache.dump()
  console.log(value) // Returns [ { key: 'personA', value: { name: 'john', age: 21 }, expiryInMs: 5000 }, { key: 'personB', value: { name: 'enoch', age: 9999 }, expiryInMs: undefined }]
}, 4000)

setTimeout(() => {
  // ---- Check cache after 7.0 seconds ----
  let value = cache.get('personA')
  console.log(value) // Return undefined as object has already expired
}, 7000)

Accessible globally, meaning that no matter what file you are using it in your NodeJS project, as long as the cache name is the same, it will be referring to the same cache:

Inside File_A.js:

// File_A.js

const ExtremeCache = require('extreme-cache')

const cache = new ExtremeCache('my-unique-cache-name') 

cache.set('cat-name', 'garfield')

Inside File_B.js:

// File_B.js

const ExtremeCache = require('extreme-cache')

const cache = new ExtremeCache('my-unique-cache-name') 

let value = cache.get('cat-name')

console.log(value) // outputs 'garfield'

API Reference

  • set(key, value, expiryInMs)

    Usage:

    const ExtremeCache = require('extreme-cache')
    
    const cache = new ExtremeCache('my-custom-cache') 
    
    // Set with an expiry
    cache.set('cat-name', 'garfield', 5000)
    
    // Set without an expiry
    cache.set('dog-name', 'odi')
    
  • get(key)

    Usage:

    const ExtremeCache = require('extreme-cache')
      
    const cache = new ExtremeCache('my-custom-cache') 
    
    cache.set('cat-name', 'garfield')
    
    let value = cache.get('cat-name')
    
    console.log(value) // outputs the value - 'garfield'
    
  • delete(key)

    Usage:

    const ExtremeCache = require('extreme-cache')
    
    const cache = new ExtremeCache('my-custom-cache') 
    
    cache.set('cat-name', 'garfield')
    
    let value = cache.delete('cat-name')
    
    console.log(value) // outputs the deleted object - { key: 'cat-name', value: 'garfield', timeoutInMs: undefined }
    
  • dump()

    Usage:

    const ExtremeCache = require('extreme-cache')
    
    const cache = new ExtremeCache('my-custom-cache') 
    
    cache.set('cat-name', 'garfield')
    
    cache.set('dog-name', 'odi', 5000)
    
    let value = cache.dump()
      
    console.log(value) // outputs the entire cache in an array - [{ key: 'cat-name', value: 'garfield', timeoutInMs: undefined }, { key: 'dog-name', value: 'odi', timeoutInMs: 5000 }]
    
  • clearAll()

    Usage:

    const ExtremeCache = require('extreme-cache')
    
    const cache = new ExtremeCache('my-custom-cache') 
    
    cache.set('cat-name', 'garfield')
      
    cache.set('dog-name', 'odi', 5000)
    
    let value = cache.dump()
    
    console.log(value) // outputs the entire cache in an array - [{ key: 'cat-name', value: 'garfield', timeoutInMs: undefined }, { key: 'dog-name', value: 'odi', timeoutInMs: 5000 }]
    
    let cacheName = cache.clearAll() // Clears the cache and returns the cache name as a string - 'my-custom-cache'
    
    value = cache.dump()
      
    console.log(value) // outputs the entire cache in an array, which will be empty by now - []
    

Tests

npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.