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

@clayder-ran/browser-cache

v0.0.1

Published

base localStorage or sessionStorage; cache data in browser;

Downloads

3

Readme

说明文档

  • 存储内容在浏览器的localStorage或sessionStorage

同步模式

  • 地址: index.js > SessionStorage 或 LocalStorage
  • expire单位是毫秒;
  • value是初始值;
  • debug开启时, 有一些打印;
  • 读取和设置数据时, 支持复合的键, 如 users[1].age
/* 存储实例 */
const store = new LocalStorage({
    key: "aaa",
    expire: 1000 * 60 * 1,
    value: {
        name: "默认名称",
        items: [{}, {}, {
            name: "默认user名称"
        }]
    },
    debug: false,
});

/* 存储 */
store.set('person', '名称')

/* 读取 */
let name = store1.get('person')

/* 监听数据更新 */
store.listen("items[2].name", (curr, prev) => {
    /* curr: 更新后的数据 */
    /* prev: 更新前的数据 */
});

/* 手动禁用当前数据, 数据有更新后, 继续可用 */
store.disable()

/* 清除 */
store.clear()

异步模式

与同步模式的差异

  • 地址: index.js > AsyncStorage
  • value属性接收Promise返回Promise的函数, 返回值是存储的数据;
  • expire标识过期后, 自动用value属性获取新数据并缓存;
  • 一般不用set方法;
/* 存储实例 */
const store = new AsyncStorage({
    key: "bbb",
    expire: 1000 * 60 * 60 * 1,
    value: () => {
        return checkLogin().then(res => {
            if (isDefObj(res)) {
                const {
                    user_info: userInfo = {}
                } = res || {};
                return userInfo;
            } else {
                return null;
            }
        });
    },
    debug: false
});

/* 读取 */
store.get('users[2]').then(info => {
    /* 第二个用户的信息: info */
})

/* 手动禁用当前数据, 数据有更新后, 继续可用 */
store.disable()

/* 清除 */
store.clear()

适配保险的缓存

  • 地址: insurance.js > CacheInsuranceStorage
  • 更适用于保险数据的缓存;
  • 基于 SessionStorage 的拓展;
  • 数据过期后, 从初始化数据中解析, 不会返回空;