<!-- Source: https://memory.svelte.page/compare/vs-keyv -->
<!-- Canonical: https://memory.svelte.page/compare/vs-keyv -->
# Memory Cache vs Keyv

A Multi-Backend Store vs an In-Process Cache

## Overview

Compare Keyv and @humanspeak/memory-cache: a pluggable async key-value layer spanning Redis, SQLite, and Postgres against a synchronous zero-dependency in-process cache with LRU eviction and method memoization.

- **Memory Cache site:** https://memory.svelte.page
- **Memory Cache npm:** https://www.npmjs.com/package/%40humanspeak%2Fmemory-cache
- **Memory Cache slug:** memory-cache
- **Category:** Multi-Backend Key-Value Store
- **Approach:** Async storage abstraction with pluggable adapters (memory, Redis, SQLite, Postgres, Mongo, and more)
- **Website:** https://keyv.org
- **GitHub:** https://github.com/jaredwray/keyv
- **npm:** https://www.npmjs.com/package/keyv

## Feature comparison

| Feature | @humanspeak/memory-cache | Keyv | Notes |
| --- | --- | --- | --- |
| Zero Dependencies | Yes | No | Keyv keeps its core small, but ships with serialization dependencies and each backend needs its own adapter package. |
| TypeScript Support | Written in TypeScript | Written in TypeScript |  |
| Synchronous API | Sync get/set — no await on the hot path | No | Keyv is Promise-based everywhere so the same code can back onto Redis or SQLite. For purely in-process caching that indirection is overhead. |
| Persistent / Shared Backends | No | Redis, SQLite, Postgres, Mongo, etcd, … | This is Keyv’s core value proposition — Memory Cache is in-process by design and does not try to compete here. |
| TTL Expiration | Per cache instance | Per-entry ttl argument on set() |  |
| LRU Eviction | Yes | Store-dependent | Keyv’s default in-memory Map never evicts; bounded behavior requires bringing an LRU-capable store yourself. |
| Wildcard / Prefix Deletion | deleteByMagicString + deleteByPrefix | clear() per namespace |  |
| Method Memoization Decorator | @cached, async-aware | No |  |
| Async Fetch De-Duplication | getOrSet() collapses concurrent lookups | No |  |
| Built-In Statistics | getStats() aggregate counters | No |  |
| Namespaces | Key prefixes + prefix deletion | First-class namespaces |  |
| Value Compression | No | @keyv/compress-brotli / gzip adapters |  |

## Memory Cache strengths

- Zero runtime dependencies — works in Node and the browser
- TypeScript-first with fully typed generics (MemoryCache<T>)
- TTL expiration and true LRU eviction in one cache — expired entries are pruned before any valid key is evicted
- Wildcard + prefix bulk invalidation (deleteByMagicString, deleteByPrefix)
- @cached decorator for method-level memoization — async-aware with in-flight de-duplication
- getOrSet() async fetch helper that de-duplicates concurrent lookups for the same key
- Lifecycle hooks (onHit, onMiss, onSet, onDelete, onExpire, onEvict) plus built-in getStats()
- Synchronous reads and writes — no await on the hot path

## Keyv strengths

- Swap storage backends (memory to Redis to SQLite) without changing call sites
- Persistence and cross-process sharing when you outgrow one process
- Per-entry TTL on every set() plus first-class namespaces
- Actively maintained with a broad, well-documented adapter ecosystem

## Memory Cache limitations

- Smaller community (newer project)
- In-process only — no persistence or multi-process sharing by design
- TTL is configured per cache instance, not per entry

## Keyv limitations

- Async API adds Promise overhead to purely in-process caching
- Default memory store is an unbounded Map — no eviction policy built in
- Values are serialized by default, a cost Memory Cache never pays in-process
- No memoization decorator, fetch de-duplication, or cache statistics

## Verdict

Keyv and Memory Cache solve different problems. Keyv is a storage abstraction: reach for it when cached state must survive restarts or be shared across processes, and you want Redis today with SQLite tomorrow. Memory Cache is a cache: bounded memory, LRU + TTL, synchronous hot-path reads, memoization, and stats, all inside one process. If you are using Keyv’s default memory store just to cache computed values, Memory Cache does that job with less ceremony and real eviction.

## Keywords

keyv alternative, keyv vs memory-cache, in-memory cache vs redis, key-value store node.js, typescript cache library, in-process caching
