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

x-cache

v0.0.1

Published

A finite key-value cache support multi cache algorithm (LRU, FIFO, LFU...).

Downloads

3

Readme

X-cache

A finite key-value cache support multi cache algorithm (LRU, FIFO, LFU...).

Support cache algorithm

| strategy | description | todo | | ------------- |:-----------------------------:| -----:| | fifo | First in First out (FIFO) | | | lru | Least Recently Used (LRU) | | | lru-k | Least Recently Used K (LRU-K) | todo | | 2q | Two queues (2Q) | todo | | lfu | Least Frequently Used (LFU) | todo | | ... | ... | ... |

Usage

$ npm install x-cache --save

Example

import {LruXCache, XCache} from 'x-cache';
// or
var XCache = require('x-cache').XCache;

const cache = new LruXCache(1000);
cache.put('elwin', 1215);
cache.put('leon', 1233);
cache.put('tom', 1234);
cache.get('elwin'); // 1215
cache.find('elwin'); // true
cache.remove('elwin'); // true
cache.getSize(); // 2
cache.getArray(); // [1234, 1233]
cache.shift();
cache.forEach((v, k, obj) => console.log(v, k)); // tom, 1234
cache.removeAll();

API

new XCache(strategy, option)

Create a new cache instance.

  • strategy: cache algorithm, such as lru, fifo..., you can see support cache algorithm for detail.
  • option: it is not always same. if you use lru strategy, the option is {limit: 1000}.

new LruXCache(limit)

Create a new cache instance using LRU cache algorithm.

  • limit: limit the size of cache

new FifoXCache(limit)

Create a new cache instance using FIFO cache algorithm.

  • limit: limit the size of cache

XCache.prototype.put(key, value): Object entry

Put the value into the cache associated with key.

  • key:
  • value:

XCache.prototype.get(key): Object value

Returns the value associated with key or undefined if not in the cache.

  • key:

XCache.prototype.shift(): Object entry

Such as array.shift().

XCache.prototype.find(key): Boolean bool

Check the key is whether in cache or not.

  • key:

XCache.prototype.remove(key): Boolean bool

Remove the value associated with key, return true if remove successful.

  • key:

XCache.prototype.removeAll()

Clear the cache.

XCache.prototype.getSize(): Number size

Returns the current size of the cache.

XCache.prototype.getArray(fromHead): Array array

Returns array {key, value}.

  • fromHead: default false

XCache.prototype.forEach(callback, fromHead)

Iterator, callback(key, value, obj).

  • fromHead: default false

Develop

$ npm install

$ npm run build

$ npm run test

Feedback

If you any questions, use Issues.

Sina Weibo: @赵小小峰

License

MIT Licence.