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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@braken/cache-file

v1.1.32

Published

somethings

Downloads

37

Readme

@braken/cache-file

Braken 框架的文件系统缓存实现,提供基于文件系统的本地缓存支持。

安装

pnpm add @braken/cache-file

特性

  • 基于文件系统的本地缓存实现
  • 支持过期时间管理
  • 自动文件清理
  • JSON 序列化
  • 内存缓存加速
  • 依赖注入集成

使用示例

import { Application } from '@braken/application';
import FileCache from '@braken/cache-file';

// 设置缓存目录
FileCache.set('./cache');

// 创建缓存实例
const cache = new FileCache();

// 写入缓存
await cache.write('/user/1', { id: 1, name: 'John' }, Date.now() + 3600000); // 1小时后过期

// 读取缓存
const user = await cache.read('/user/1');

// 检查缓存是否存在
const exists = cache.has('/user/1');

// 获取过期时间
const expireTime = cache.expire('/user/1');

// 删除缓存
await cache.delete('/user/1');

API

FileCache 类

主要的缓存实现类,提供以下功能:

  • 缓存读写
  • 过期时间管理
  • 文件系统管理
  • 内存缓存加速
  • 依赖注入集成

静态方法

set

设置缓存目录:

static set(directory: string)

实例方法

write

写入缓存:

async write(key: string, value: any, time: number = 0)

read

读取缓存:

async read(key: string)

expire

获取过期时间:

expire(key: string)

delete

删除缓存:

async delete(key: string)

has

检查缓存是否存在:

has(key: string)

实现细节

  • 使用 JSON 文件存储缓存数据
  • 支持路径格式的键名
  • 自动创建目录结构
  • 定期清理过期文件
  • 使用内存缓存加速访问
  • 支持文件系统监控

注意事项

  • 需要确保缓存目录有写入权限
  • 键名会被转换为文件路径
  • 所有值都会被 JSON 序列化
  • 过期时间使用毫秒为单位
  • 文件系统操作是异步的

依赖注入

@Application.Injectable
class MyService {
  @Application.Inject(FileCache)
  private readonly cache: FileCache;
}

许可证

MIT