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

@lostlz/cache-js

v1.0.12

Published

一款简易版本地储存插件。

Downloads

14

Readme

CacheJs

概述

一款简易版本地储存插件。

  • 支持基本类型、及能够通过JSON.stringify序列化的对象
  • 支持设置默认值和过期时间
  • 支持设置key前缀
  • 在web环境支持localStorage/sessionStorage
  • 兼容微信小程序

安装

npm i @lostlz/cache-js -S

微信小程序安装完需要构建npm

示例

web环境和小程序环境调用方式相同。

CacheJs

持久化缓存,对应localStorage。

import CacheJs from "@lostlz/cache-js";

// 写入一个对象缓存
CacheJs.set("obj1",{a:1,b:2,c:3});
// 写入一个对象并缓存一分钟
CacheJs.set("obj2",{a:1,b:2,c:3,d:4},new Date().getTime()+60*1000);
// 获取一个缓存,如果缓存不存在,或者超时返回{d:4}
const obj3 = CacheJs.get("obj3",{d:4});
console.log("obj3",obj3)

CacheJs.session

session缓存,对应sessionStorage。

小程序环境也可以使用,数据存在全局Map中,应用周期内都有效。

import CacheJs from "@lostlz/cache-js";

// 写入一个对象缓存
CacheJs.session.set("obj1",{a:1,b:2,c:3});
// 写入一个对象并缓存一分钟
CacheJs.session.set("obj2",{a:1,b:2,c:3,d:4},new Date().getTime()+60*1000);
// 获取一个缓存,如果缓存不存在,或者超时返回{d:4}
const obj3 = CacheJs.session.get("obj3",{d:4});
console.log("obj3",obj3)

方法

set(key,value,expire)

添加一个缓存,如果存在会覆盖。

参数:

  • key:关键字(必填)
  • value:需要存储的内容。支持基本类型、及能够通过JSON.stringify序列化的对象。(必填)
  • expire:超过expire(时间戳/ms)清除缓存,默认永久。(非必填)

get(key,defaultValue)

获取一个缓存,如果缓存不存在,返回默认值.

参数:

  • key:关键字。(必填)
  • defaultValue:默认值,如果缓存不存在,返回此值。(非必填)

setPrefixKey(prefixKey)

设置key的前缀,如果设置,实际key=prefixKey+key

参数:

  • prefixKey:前缀(必填),默认为空

delete(key)

删除一个缓存

参数:

  • key:关键字(必填)

clear()

清空全部缓存