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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-smple-cache

v0.0.0

Published

A simple nodejs cache manager

Readme

#How to use

##Init

Cache.createCache([cache algorithm], [cache size])

  • About cache algorithm: you have two choice "LRU" or "LFU", of course you can add your own algorithm. If you not sure which algorithm, you can choose the following manage mode.
var cache = require("Cache");
Cache.createCache("LRU", 100 * 100 * 10);

##Set

cache.set(key, value[, expire(millisecond)])

cache.set("key", "value", 1000 * 60);

##Get

cache.get(key)

cache.get("key") // value or null

##Clear

cache.clear()

##Manage Mode

If you are not sure which cache replacement algorithm is you need, you can try this model, it will caculate the recently 100 * 100 * 3 get hit rate in different algorithm.And according the hit rate choose the higher algorithm one:

var CacheManage = require("./Manage");
CacheManage.set("key", "value", 1000 * 60);

前提有两个,首先你的缓存管理程序是用javascript书写的node.js程序

为什么需要自己写缓存管理,

自己写缓存管理的优势在于更快[测试],

但劣势也很明显,就是无法做到多进程之间的通信

你可能说可以使用socket,不错,因为Redis走的就是socket通信

但这样的代价是会使效率变低

所以说如果你的缓存管理是独享,只存在于一个node.js进程中,那么可以考虑自己构造一个

自己写一个缓存管理工具,有一个问题是 如何控制 缓存使用内存空间的大小

如果在Redis中,你只要进行Config中的maxmemory即可,但是在node.js中,我们没法设定它的运行使用内存大小

我们可以转向另一个东西,数据条数,通过控制数据条数,来间接控制数据大小,虽然不够准确

##大纲

  1. Redis与我写的缓存管理 set操作效率,比较,比较平均每条操作要多少时间/每秒能进行多少操作 (即使是在使用pipline的情况下)

  2. 我自己的缓存算法需要注意的地方

    • 摒弃数组,使用链表
    • 分离出缓存的索引
    • n与logn 与 delete 操作
  3. 实现最基本的LRU算法

  4. LRU算法的局限性(LFU算法的优势)

  5. 机器学习算法