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

@ureq/lib-cache-store

v0.0.3

Published

Cache store implementations for universal request library

Readme

@ureq/lib-cache-store

缓存存储实现,提供内存缓存和 Storage 缓存。

安装

npm install @ureq/lib-cache-store
# 或
pnpm add @ureq/lib-cache-store

使用

MemoryCacheStore

内存缓存实现,适用于浏览器和 Node.js。

import { Request } from '@ureq/core';
import { FetchRequestor } from '@ureq/impl-fetch';
import { MemoryCacheStore } from '@ureq/lib-cache-store';

const cacheStore = new MemoryCacheStore();

const request = new Request(
  new FetchRequestor(),
  {
    cache: {
      store: cacheStore,
      ttl: 60000  // 60 秒
    }
  }
);

StorageCacheStore

基于 Web Storage API 的缓存实现(localStorage/sessionStorage)。

import { StorageCacheStore } from '@ureq/lib-cache-store';

// 使用 localStorage
const localCache = new StorageCacheStore(localStorage);

// 使用 sessionStorage
const sessionCache = new StorageCacheStore(sessionStorage);

const request = new Request(
  new FetchRequestor(),
  {
    cache: {
      store: localCache,
      ttl: 3600000  // 1 小时
    }
  }
);

API

MemoryCacheStore

class MemoryCacheStore implements CacheStore {
  get<T>(key: string): Promise<T | null>;
  set<T>(key: string, value: T, ttl: number): Promise<void>;
  delete(key: string): Promise<void>;
  clear(): Promise<void>;
}

StorageCacheStore

class StorageCacheStore implements CacheStore {
  constructor(storage: Storage);
  
  get<T>(key: string): Promise<T | null>;
  set<T>(key: string, value: T, ttl: number): Promise<void>;
  delete(key: string): Promise<void>;
  clear(): Promise<void>;
}

特性

MemoryCacheStore

  • ✅ 快速访问
  • ✅ 支持浏览器和 Node.js
  • ✅ 自动过期清理
  • ⚠️ 数据不持久化

StorageCacheStore

  • ✅ 数据持久化
  • ✅ 跨页面共享(localStorage)
  • ✅ 自动过期清理
  • ⚠️ 仅支持浏览器
  • ⚠️ 存储空间有限(通常 5-10MB)

示例

基础用法

import { MemoryCacheStore } from '@ureq/lib-cache-store';

const cache = new MemoryCacheStore();

// 存储数据
await cache.set('key', { data: 'value' }, 60000);

// 获取数据
const data = await cache.get('key');

// 删除数据
await cache.delete('key');

// 清空缓存
await cache.clear();

持久化缓存

import { StorageCacheStore } from '@ureq/lib-cache-store';

const cache = new StorageCacheStore(localStorage);

// 数据会保存到 localStorage
await cache.set('user', { id: 1, name: 'John' }, 3600000);

// 刷新页面后仍然可以获取
const user = await cache.get('user');

自定义缓存实现

import { CacheStore } from '@ureq/core';

class RedisCacheStore implements CacheStore {
  async get<T>(key: string): Promise<T | null> {
    // 从 Redis 获取
  }
  
  async set<T>(key: string, value: T, ttl: number): Promise<void> {
    // 存储到 Redis
  }
  
  async delete(key: string): Promise<void> {
    // 从 Redis 删除
  }
  
  async clear(): Promise<void> {
    // 清空 Redis
  }
}

文档

查看完整文档:https://sunny-117.github.io/ureq

License

MIT