Socket
Book a DemoInstallSign in
Socket

hl-cache

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hl-cache

A variant of clock cache for implementing shared session cache.

0.1.1
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

HLCache (Half-life cache)

This is a variant of Clock cache algorithm that keeps a ghost copy for an extended period of time. It could be useful for implementing shared session cache.

Build Status NPM version License

Install

$ npm install hl-cache

API

  • new HLCache([options]) Create a cache pool.
var cache = new HLCache({
	 // maximum size of the cache
	max: 2000,
	 // cache entry time-to-live in milliseconds
	lifespan: 2000
});

If the number of items in the cache pool exceeds max, the item will not be store in the cache.

  • HLCache::get(key[, timestamp])

Get the value by key. timestamp is optional, it is used to indicate the time the visit comes from. If no value is provided, timestamp is set to Date.now().

  • HLCache::set(key, value[, timestamp])

Set the value of key to value. timestamp is optional, it is used to indicate the time the visit comes from. If no value is provided, timestamp is set to Date.now().

  • HLCache::has(key)

Check if a key is in the cache.

  • length

Return total length of objects in cache.

Running on Node.js <= 0.10.x

This package use Map and es6-map to polyfill Map on old version of Node.

es6-map is install as optionalDependencies. The dependencies section of your application's package.json file must contain es6-map in order for the polyfill to work.

Test

$ npm test

Half-life cache algorithm

Half-life cache algorithm is a variant of clock cache algorithm that keeps a ghost copy for an extended period of time.

Half-life cache could (almost) guarantees consistent read in cache’s lifespan, which could be useful for implementing shared session cache.

License

Copyright (c) 2015 Jingwei "John" Liu

Licensed under the MIT license.

Keywords

cache

FAQs

Package last updated on 03 Jul 2015

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.