Skip to content
keypal
Esc
↑↓navigate↵open⌘Jpreview
On this page

Memory

The default in-process store, for tests and local development

Memory storage keeps keys in Maps inside the process. It is the default: with no storage option, keypal uses it. It needs no setup and no dependencies.

Keys are lost when the process exits, and every process has its own store. Use it for tests, scripts and local development, not for production.

Setup

import { createKeys } from 'keypal'

// The default
const keys = createKeys({ prefix: 'sk_' })

// The same, spelled out
const explicit = createKeys({ prefix: 'sk_', storage: 'memory' })

Each createKeys call with memory storage gets its own empty store. To share one store between managers, for example in a test, create it yourself:

import { createKeys } from 'keypal'
import { MemoryStore } from 'keypal/memory'

const store = new MemoryStore()

const issuer = createKeys({ prefix: 'sk_', storage: store })
const verifier = createKeys({ prefix: 'sk_', storage: store })

Behavior

  • Lookups by hash, id, owner and tag use indexes, so none of them scan every key.
  • save throws if the id or the key hash already exists.
  • Records are copied in and out, so changing a returned record doesn’t change the stored key.
  • Tags are stored lowercase, as in every other store.
  • Audit logs are supported and kept in memory with the keys.

For persistent storage, use Redis or a SQL adapter such as Drizzle.

Was this page helpful?