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

@hm-soft/ttl-cache

v0.1.0

Published

TTL 만료 + LRU 인메모리 캐시 — getOrSet/비동기 메모이즈, 시간 주입 가능 (의존성 0)

Readme

@hm-soft/ttl-cache

TTL 만료 + LRU 인메모리 캐시. 의존성 0, 시간 주입 가능(테스트 친화).

설치

npm install @hm-soft/ttl-cache

사용

import { TtlCache } from "@hm-soft/ttl-cache";

const cache = new TtlCache<string, User>({ ttlMs: 60_000, maxSize: 1000 });

cache.set("u1", user);
cache.get("u1");          // User | undefined (만료 시 undefined)
cache.has("u1");

// API 호출 결과 메모이즈 (60초 캐시)
const user = await cache.getOrSetAsync("u2", () => fetchUser("u2"));

// 동기 계산 메모이즈
const total = cache.getOrSet("sum", () => heavyCompute());

API

| 멤버 | 설명 | |------|------| | new TtlCache({ ttlMs?, maxSize?, now? }) | 기본 TTL·용량·시간함수 | | set(key, value, ttlMs?) | 저장(항목별 TTL 가능) | | get(key) | 조회(만료면 undefined) | | has(key) | 유효 키 존재 여부 | | delete(key) / clear() | 제거 | | prune() | 만료 항목 일괄 정리 | | size / keys() | 유효 항목 수/키 | | getOrSet(key, factory, ttlMs?) | 없으면 계산 후 캐시 | | getOrSetAsync(key, factory, ttlMs?) | 비동기 메모이즈 |

  • ttlMs 0 또는 미지정 → 기본 만료 없음 (항목별 set(k,v,ttl)로 개별 지정 가능)
  • maxSize 초과 시 가장 오래 안 쓴 항목(LRU)부터 제거
  • now를 주입하면 시간 의존 로직을 결정적으로 테스트 가능

License

Apache-2.0