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

v1.1.32

Published

somethings

Readme

@braken/cache

Braken 框架的缓存模块,提供多级缓存支持。

安装

pnpm add @braken/cache

特性

  • 多级缓存支持
  • 缓存同步
  • 过期时间管理
  • 缓存查找
  • 缓存重写
  • 依赖注入集成

使用示例

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

// 创建缓存实例
const fileCache = new FileCache();
const redisCache = new IORedisCache();

// 配置缓存服务器
CacheServer.set([fileCache, redisCache]);

// 使用缓存
@Application.Injectable
class MyService {
  @Application.Inject(CacheServer)
  private readonly cache: CacheServer;

  async getUser(id: string) {
    // 尝试从缓存读取
    const cached = await this.cache.read(`user:${id}`);
    if (cached) {
      return cached;
    }

    // 从数据库读取
    const user = await this.fetchUserFromDB(id);

    // 写入缓存
    await this.cache.write(`user:${id}`, user, Date.now() + 3600000);

    return user;
  }

  async updateUser(id: string, data: any) {
    // 更新数据库
    await this.updateUserInDB(id, data);

    // 更新缓存
    await this.cache.rewrite(`user:${id}`, data, Date.now() + 3600000, 2);
  }
}

API

CacheServer 类

主要的缓存服务器类,提供以下功能:

  • 多级缓存管理
  • 缓存同步
  • 过期时间管理
  • 缓存查找
  • 缓存重写
  • 依赖注入集成

静态方法

set

设置缓存配置:

static set(props: CacheProps[])

实例方法

write

写入缓存:

async write(key: string, value: any, expire?: number)

read

读取缓存:

async read(key: string)

has

检查缓存是否存在:

async has(key: string)

delete

删除缓存:

async delete(key: string)

expire

获取过期时间:

async expire(key: string)

find

查找缓存:

async find(key: string)

rewrite

重写缓存:

async rewrite(key: string, value: any, expire: number, i: number)

get

获取指定索引的缓存:

get<T = any>(index: number): CacheProps<T>

实现细节

  • 支持多级缓存
  • 缓存同步机制
  • 过期时间管理
  • 缓存查找策略
  • 缓存重写机制
  • 依赖注入集成

注意事项

  • 需要正确配置缓存
  • 处理缓存同步
  • 管理过期时间
  • 处理缓存失效
  • 优化缓存性能

依赖注入

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

许可证

MIT