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

@micl/server-racache

v0.1.7

Published

micl server cache

Readme

@micl/server-racache

npm version npm downloads license

提供时间敏感的内存缓存,支持本地文件快照存储。适用于 Node.js 服务端应用的数据缓存管理。

✨ 特性

  1. 提供时间敏感的缓存检索和存储功能
  2. 内存存储 + 本地文件快照持久化
  3. 自动过期和自动清理机制
  4. 支持自动存储和自动加载
  5. 完整的 TypeScript 类型支持
  6. 单例模式,全局统一管理

📦 安装

npm install @micl/server-racache
# or
pnpm add @micl/server-racache
# or
yarn add @micl/server-racache

🎯 快速使用

JavaScript

const MraCache = require('@micl/server-racache');

// 配置缓存
MraCache.config({
  expireTime: '1d',
  storePath: './cache-snapshots.json',
  autoStore: true,
  autoClear: true
});

// 设置数据
MraCache.set('user_data', { name: 'John Doe', age: 30 });

// 设置带过期时间的数据
MraCache.set('temp_data', { id: 1 }, '30m');

// 获取数据
const userData = MraCache.get('user_data');

// 移除数据
MraCache.remove('user_data');

// 清空所有数据
MraCache.clearAll();

// 保存缓存快照
MraCache.store('./cache-snapshots.json');

// 加载缓存快照
MraCache.load('./cache-snapshots.json');

TypeScript

const MraCache = require('@micl/server-racache');

interface User {
  name: string;
  age: number;
}

// 配置缓存
MraCache.config({
  expireTime: '1d',
  storePath: './cache-snapshots.json',
  autoStore: true,
  autoClear: true
});

// 设置数据
MraCache.set<User>('user_data', { name: 'John Doe', age: 30 });

// 获取数据
const userData = MraCache.get<User>('user_data');

📚 API 参考

MraCache 配置

MraCacheOptionInterface

| 配置项 | 类型 | 默认值 | 描述 | |--------|------|--------|------| | expireTime | string | '1h' | 默认过期时间(格式:1d1h1m) | | storePath | string | '' | 默认快照存储路径 | | autoStore | boolean | false | 是否自动存储 | | autoClear | boolean | false | 是否自动清理过期数据 |

config(options: MraCacheOptionInterface): void

更新全局配置设置。

参数:

  • options - 配置选项
MraCache.config({
  expireTime: '1d',
  storePath: './cache-snapshots.json',
  autoStore: true,
  autoClear: true
});

缓存操作

get<T>(key: string): T | undefined

从缓存中检索数据。

参数:

  • key - 缓存数据的唯一标识符

返回: 缓存的数据(如果存在且未过期)

const data = MraCache.get&lt;User&gt;('user_data');

set<T>(key: string, data: T, expireTime?: string): string

在缓存中存储数据,可指定过期时间。

参数:

  • key - 缓存数据的唯一标识符
  • data - 要存储的数据
  • expireTime (可选) - 过期时间(格式:1d1h1m

返回: 存储数据的唯一标识符

// 带自定义过期时间
const uuid = MraCache.set('user_data', { name: 'John Doe' }, '2h');

set<T>(data: T): string

在缓存中存储数据,自动生成唯一标识符。

参数:

  • data - 要存储的数据

返回: 自动生成的唯一标识符

const uuid = MraCache.set({ name: 'John Doe' });

remove(key: string): string | undefined

从缓存中移除数据。

参数:

  • key - 要移除数据的唯一标识符

返回: 移除数据的唯一标识符,如果未找到则为 undefined

const uuid = MraCache.remove('user_data');

clearAll(): void

清空缓存中的所有数据。

MraCache.clearAll();

快照管理

store(path?: string): boolean

将当前缓存数据保存为快照。

参数:

  • path (可选) - 快照存储路径

返回: 保存成功返回 true,否则返回 false

MraCache.store('./cache-snapshots.json');

load(path?: string): void

从指定路径加载快照。

参数:

  • path - 快照加载路径
MraCache.load('./cache-snapshots.json');

🕐 时间格式

支持的时间格式:

| 格式 | 说明 | |------|------| | 1s | 1 秒 | | 1m | 1 分钟 | | 1h | 1 小时 | | 1d | 1 天 |

🤝 贡献

欢迎提交 Issue 和 Pull Request 来完善这个模块。

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。

Copyright (c) alexgogoing [email protected]

📞 支持

如有问题或建议,请提交 Issue 或联系维护者。


@micl/server-racache - 时间敏感的内存缓存,简单高效 🚀