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-drive/cache

v1.3.0

Published

页端缓存模块

Downloads

10

Readme

页端缓存模块

缓存数据统一调用模块,支持不同实例使用不同的缓存类型,目前支持 localStorage、sessionStorage、内存缓存。

配置

  • type 缓存类型,可直接传入类型值或者通过 import {CacheType} from "@x-drive/cache" 后使用 CacheType 中的名称指定,默认使用 sessionStorage
    • 0 localStorage
    • 1 sessionStorage
    • 2 内存。内存型的缓存在第一次被实例化的时候才会被注册到模块中,因此使用者可以在一开始的时候使用 register 注册自己的内存型缓存,默认内存缓存的取值是 2
  • expires 全局过期时间
  • prefix 缓存key前缀
  • maxStack 限制上限

使用

存储数据

set(key: string, value: any, conf?: DataConf): this;

  • key 数据键值
  • value 数据
  • conf 数据缓存配置
    • expires 单条数据过期时间
    • conditions 缓存生效条件
Cache.set("test", 123456);

获取存储的数据

get(key: string): any;

  • key 存储数据的键值
Cache.get("test");

删除已经存储的数据

del(key: string): this;

  • key 存储数据的键值
Cache.del("test");

存储一条一次性消费的数据

once(key: string, value: any, conf?: DataConf): this;

配置中的 once 字段会被强制设置为 true

  • key 数据键值
  • value 数据
  • conf 数据缓存配置
    • expires 单条数据过期时间
    • conditions 缓存生效条件
Cache.once("test", 123456);

是否包含指定数据

has(key: string, validity: boolean = false): boolean;

  • key 存储数据的键值
  • validity 是否进行数据有效性校验
Cache.has("test");

删除已经存储的数据

tidy(): this;

Cache.tidy();

注册缓存模块

模块提供了 register 方法用于注册新的缓存模块

import Cache, { CacheType, register } from "@x-drive/cache";
// 业务使用的特殊缓存
import TaroCache from "@components/cache/@mods/t-cache";
// 注册缓存
register("taro", TaroCache);
// 使用
const TaroCache = new Cache({
    // 通过 CacheType 指定使用的缓存类型
    "type": CacheType.taro
});