Socket
Socket
Sign inDemoInstall

base-cache

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    base-cache

A simple node.js base module for creating cache tables based on hashtables with a max size.


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

base-cache

Build Status

A simple node.js base module for creating cache tables, based on hashes/keys. This module was written for the light-router cache manager, so performance is a concern in this module :)

##Install

npm install base-cache

##How to use

  • This cache manager does not have a max_age property, the only option is to set a max_size for the cache table. By default its 10000.

cache.js

var Cache = require('base-cache')

//Create some cache tables
var Table = {
    dogs: new Cache({max_size: 10000}),
    cats: new Cache({max_size: 5000})
}

//Export the tables
module.exports = Table

logic.js

var cache = require('./cache.js')

//Select a table
var dogs = cache["dogs"]

//Try to find a cache
var hit = dogs.find("Zeus")

if(typeof hit !== 'undefined') {
    console.log(hit)
}
//Not found in cache, add to cache
else {
    dogs.add("Zeus", {
        age: 3,
        gender: 'male',
        breed: 'rottweiler'
    })
}

##Methods

Cache.Constructor(options)

This initializes a new cache hash table an returns it. You can send an optional options object.

var cache = new Cache({
    max_size: 10 //Default: 10000
})

cache.add(key, value)

Add something to the cache table or update if exists.

cache.add('bananas.stock', 1000)

cache.find(key)

Find something in the cache table.

cache.find('bananas.stock')

cache.clear()

Clears the given cache table.

cache.clear()

cache.size()

Return the current size of the cache table

cache.size()

##Notes

  • Once the cache table hits its max_size it will start replacing the older cache elements.

##Contributions

Keywords

FAQs

Last updated on 05 Jun 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc