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

@croco/cache-core

v0.0.2

Published

Croco 프레임워크용 캐시 추상화 패키지입니다. 인메모리 LRU 캐시, stampede protection, TTL 관리, 패턴 무효화, 분산 캐시 인터페이스를 제공합니다.

Downloads

362

Readme

@croco/cache-core

Croco 프레임워크용 캐시 추상화 패키지입니다. 인메모리 LRU 캐시, stampede protection, TTL 관리, 패턴 무효화, 분산 캐시 인터페이스를 제공합니다.

설치

npm install @croco/cache-core
# 또는
pnpm add @croco/cache-core

기능

  • 진정한 LRU: 읽기 접근 시 순서를 갱신하는 eviction 정책
  • Stampede protection: 동일 키 동시 요청을 singleflight로 병합
  • TTL(ms): lazy eviction + 주기적 정리 지원
  • 통계 조회: hit, miss, eviction, size 집계
  • 고수준 API: getOrSet(), invalidatePattern(), warmup()
  • 분산 캐시 확장점: 락 획득과 무효화 전파 인터페이스 제공

사용법

InMemoryCacheStore

import { InMemoryCacheStore } from "@croco/cache-core";

const cache = new InMemoryCacheStore<string>({
  maxEntries: 500,
  cleanupIntervalMs: 30_000,
});

await cache.set("user:1", "active-user", 5_000);

const value = await cache.get("user:1");
const stats = cache.getStats();

getOrSet으로 singleflight 로딩

import { InMemoryCacheStore } from "@croco/cache-core";

const cache = new InMemoryCacheStore<{ id: string; name: string }>({ maxEntries: 1000 });

const user = await cache.getOrSet(
  "user:42",
  async () => {
    return await userRepository.findById("42");
  },
  {
    ttlMs: 60_000,
  },
);

warmup과 패턴 무효화

import { InMemoryCacheStore } from "@croco/cache-core";

const cache = new InMemoryCacheStore<string>({ maxEntries: 1000 });

await cache.warmup([
  { key: "tenant:1:profile", value: "ready", ttlMs: 10_000 },
  { key: "tenant:1:settings", value: "loaded" },
]);

await cache.invalidatePattern("tenant:1:*");

데코레이터 기반 캐싱

import { Cacheable, CacheEvict, InMemoryCacheStore } from "@croco/cache-core";

const cache = new InMemoryCacheStore<string>({ maxEntries: 1000 });

class UserService {
  @Cacheable({ store: cache, namespace: "user-service", ttl: 60_000 })
  async getUser(id: string): Promise<string> {
    return `user-${id}`;
  }

  @CacheEvict({ store: cache, key: "user-service:getUser:*" })
  async updateUser(_id: string): Promise<void> {}
}

API 요약

타입

| 타입 | 설명 | | ----------------------------- | --------------------------- | | Cache<K, V> | 제네릭 캐시 계약 | | CacheStore<K, V> | 하위 호환용 추상 베이스 | | CacheStats | hit/miss/eviction/size 통계 | | CacheWarmupEntry<K, V> | warmup 항목 | | DistributedCacheStore<K, V> | 분산 캐시 확장 계약 | | DistributedCacheLock | 분산 락 해제 핸들 |

주요 메서드

| 메서드 | 설명 | | --------------------------------- | ------------------------------ | | get(key) | 값 조회 및 LRU 갱신 | | set(key, value, ttlMs?) | 값 저장 | | getOrSet(key, loader, options?) | 캐시 미스 시 singleflight 로딩 | | invalidatePattern(pattern) | 와일드카드 패턴 무효화 | | warmup(entries) | 미리 캐시 적재 | | pruneExpired() | 만료 항목 수동 정리 | | getStats() | 통계 조회 |

라이선스

MIT