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

lfustorage

v1.1.0

Published

a lfu-storage plugin

Downloads

6

Readme

LFUStorage

基于LFU(最近最久未使用)策略和localStorage设计的web存储系统,改系统支持两种方式进行数据置换:

  • 基于存储数量
  • 基于内存大小

Install

npm install lfu-storage --save

Usage

import LFUStorage from 'lfu-storage'
storage = new LFUStorage(namespace)  // namespace 可选

storage.nameSpace(name).size(maxSize).expire(secs)
storage.set(key, val)
storage.get(key)

Worker API

|Api|Params|Description| | :-----| :---- | :---- | |nameSpace|name|设置存储实例的命名空间。name: String/必须(对应localStorage的key值)| |max|num|设置存储数量上限。max:Number/可选,默认值是50| |size|val|设置存储空间上限|val: Number/非必须,默认值是4MB| |expire|sec|设置过期时间|sec: Number/非必须。默认值7days| |getMax|/|获取存储数量上限| |getSize|/|获取存储空间上限| |getRemainMax|/|获取剩余存储数量| |getRemainSize|/|获取剩余存储空间| |getExpire|/|获取过期时间| |set|key,val|存储数据项。key: String/必须,val: 必须| |get|key|获取数据项。key: String/必须| |remove|key|删除数据项。key: String/必须| |has|key|判断是否存在数据项。key: String/必须| |keys|/|获取所有数据项的key值| |values|/|获取所有数据项的值| |entries|/|获取存储数据的键值对数组,结果基于LFU排序| |clear|/|清除所有存储数据| |on|evt,cb|订阅事件。evt: String,取值范围['expire', 'set', 'remove', 'clear', 'overflow'],cb: callback| |off|evt|取消订阅事件。evt: String。取值范围['expire', 'set', 'remove', 'clear', 'overflow']|

Example

// 本地聊天缓存系统
import LFUStorage from 'lfu-storage'

const chatStorage = new LFUStorage('CHAT_MESSAGE')
chatStorage.max(10).expire(3 * 24 * 60 * 60) // 设置聊天信息缓存上限10条(个用户)

// 订阅溢出事件
chatStorage.on('overflow', (res) => { console.log(`storage overflow,delete keys: ${res}`) })

// 订阅过期事件
chatStorage.on('expire',(namespace) => { console.log(`${namespace} is expired`) })

// 取消订阅
chatStorage.off('expire')

chatStorage.set(userId, messages)