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

@casfa/storage-memory

v0.1.0

Published

In-memory storage provider for CAS (testing)

Readme

@casfa/storage-memory

基于内存的 CAS 存储提供者。

安装

bun add @casfa/storage-memory

概述

基于内存的 CAS(内容寻址存储)存储提供者。适用于测试、开发和临时存储场景。

⚠️ 警告:数据不会持久化,进程退出后将丢失。仅用于测试和开发。

使用方法

基本用法

import { createMemoryStorage } from '@casfa/storage-memory';

const storage = createMemoryStorage();

// 存储数据
await storage.put('node:abcd1234...', data);

// 检索数据
const data = await storage.get('node:abcd1234...');

// 检查是否存在
const exists = await storage.has('node:abcd1234...');

// 删除
const deleted = await storage.delete('node:abcd1234...');

带检查功能(测试用)

import { createMemoryStorageWithInspection } from '@casfa/storage-memory';

const { storage, inspect } = createMemoryStorageWithInspection();

// 正常使用存储
await storage.put('node:abcd1234...', data);

// 检查内部状态(测试时很有用)
console.log(inspect.size());       // 条目数量
console.log(inspect.keys());       // 所有已存储的键
console.log(inspect.totalBytes()); // 已存储的总字节数
inspect.clear();                   // 清除所有数据

设置大小限制

import { createMemoryStorage } from '@casfa/storage-memory';

const storage = createMemoryStorage({
  maxSize: 100 * 1024 * 1024,  // 100MB 限制
});

配置

interface MemoryStorageConfig {
  // 可选:最大存储字节数
  // 超出时可能淘汰最旧的条目
  maxSize?: number;
  
  // 可选:最大条目数
  maxItems?: number;
}

API 参考

函数

  • createMemoryStorage(config?) - 创建基本内存存储
  • createMemoryStorageWithInspection(config?) - 创建带检查工具的存储

StorageProvider 接口

interface StorageProvider {
  get(key: string): Promise<Uint8Array | null>;
  put(key: string, data: Uint8Array): Promise<void>;
  has(key: string): Promise<boolean>;
  delete(key: string): Promise<boolean>;
}

Inspection 接口

interface StorageInspection {
  size(): number;           // 条目数量
  keys(): string[];         // 所有键
  totalBytes(): number;     // 已使用的总存储量
  clear(): void;            // 清除所有数据
}

使用场景

  • 单元测试:快速、隔离的测试存储
  • 集成测试:可预测的存储行为
  • 开发环境:无需文件系统即可快速迭代
  • 缓存层:与持久化存储组合使用

示例:测试

import { describe, it, expect, beforeEach } from 'bun:test';
import { createMemoryStorageWithInspection } from '@casfa/storage-memory';

describe('MyService', () => {
  let storage: StorageProvider;
  let inspect: StorageInspection;

  beforeEach(() => {
    const result = createMemoryStorageWithInspection();
    storage = result.storage;
    inspect = result.inspect;
  });

  it('should store data', async () => {
    const service = new MyService(storage);
    await service.saveData('test');
    
    expect(inspect.size()).toBe(1);
  });
});

相关包

  • @casfa/storage-core - 核心类型与工具
  • @casfa/storage-fs - 文件系统存储(用于生产环境)
  • @casfa/storage-s3 - S3 存储(用于云端部署)

许可证

MIT