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

@nodellmcache/core

v1.0.0

Published

Shared interfaces, types, and utilities for NodeLLMCache — AI memory infrastructure for Node.js

Readme

@nodellmcache/core

Shared interfaces, types, and utilities for NodeLLMCache — AI memory infrastructure for Node.js.

This is the central package every other @nodellmcache/* package depends on. It has zero external dependencies and exports only contracts and small, pure utilities. You rarely install it directly; a feature package (e.g. @nodellmcache/prompt-cache) pulls it in.

Install

npm install @nodellmcache/core

What's inside

  • InterfacesStorageAdapter, VectorStoreAdapter, CompressionEngine, CacheEntry, CacheMetadata, MetricsSink, CacheOptions
  • TypesCacheType, LLMProvider, CompressionAlgo, DataHint
  • KeyBuilder — deterministic, hashed cache keys
  • TTLManager — expiry arithmetic and sliding windows
  • Serializer / JsonSerializer — pluggable value encoding
  • BaseCacheManager — the cache-aside base class for every feature cache
  • Error hierarchyNodeLLMCacheError and typed subclasses

Quick start

Building keys

Keys follow the format {type}:{provider}:{model}:{sha256}. The raw input is normalized (trimtoLowerCase → collapse whitespace) and hashed, so raw prompt text never appears in a key.

import { KeyBuilder } from '@nodellmcache/core'

KeyBuilder.build('prompt', 'openai', 'gpt-4o', 'Hello   World')
// 'prompt:openai:gpt-4o:<sha256-of "hello world">'

Implementing a storage adapter

import type { StorageAdapter, CacheEntry, AdapterStats } from '@nodellmcache/core'

class MyAdapter<T> implements StorageAdapter<T> {
  async get(key: string): Promise<CacheEntry<T> | null> { /* ... */ }
  async set(key: string, entry: CacheEntry<T>, ttl?: number): Promise<void> { /* ... */ }
  async delete(key: string): Promise<void> { /* ... */ }
  async clear(): Promise<void> { /* ... */ }
  async has(key: string): Promise<boolean> { /* ... */ }
  async stats(): Promise<AdapterStats> { /* ... */ }
}

Building a feature cache

BaseCacheManager provides the cache-aside getOrGenerate flow, key building, TTL handling, hit/miss accounting, and metric emission. Subclasses only declare their cacheType.

import { BaseCacheManager } from '@nodellmcache/core'

class PromptCache extends BaseCacheManager<string> {
  protected readonly cacheType = 'prompt' as const
}

const cache = new PromptCache({ adapter: myAdapter, defaultTTL: 3_600_000 })

const answer = await cache.getOrGenerate(
  'Explain Redis in one paragraph',
  () => callTheModel(),
  { provider: 'openai', model: 'gpt-4o' },
)

API summary

| Symbol | Kind | Purpose | |--------|------|---------| | KeyBuilder.build/normalize/hash | class (static) | Cache key generation | | TTLManager.computeExpiresAt/isExpired/remaining/slide | class (static) | TTL arithmetic | | JsonSerializer | class | Default JSON value codec (implements Serializer) | | BaseCacheManager | abstract class | Cache-aside base for feature caches | | StorageAdapter<T> | interface | Backend contract | | VectorStoreAdapter<M> | interface | Vector DB contract | | CompressionEngine | interface | Compression contract | | MetricsSink | interface | Metrics emission contract | | NodeLLMCacheError + subclasses | classes | Typed error hierarchy |

Notes

  • The architecture specifies MessagePack as the primary serialization format. To keep core dependency-free, this package ships only JsonSerializer; a MessagePack Serializer can be supplied by an optional package and injected wherever a Serializer is accepted.
  • MetricsSink defaults to a no-op (noopMetrics). Wire in @nodellmcache/observability to collect real metrics.

License

MIT