Registry / database / graphile-cache

graphile-cache

JSON →
library3.13.0jsnpmunverified

Graphile Cache provides a simple, performance-oriented LRU cache primarily designed for use with PostGraphile v5 and Graphile Worker. It automatically integrates with PostGraphile's pool lifecycle to clean up cache entries when database connections are released, preventing stale data and memory leaks. Current stable version 3.13.0 is maintained and released regularly as part of the Constructive monorepo. Key differentiators: automatic pool cleanup, focused scope for Graphile ecosystem, and minimal overhead compared to general-purpose caches.

npm install graphile-cache
INSTALL
IMPORT
SIG · GRAPHILE-CACHE
G
graphile-cache
databasejavascriptv3.13.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getCache
import { getCache } from 'graphile-cache'
const getCache = require('graphile-cache').getCache
Package is ESM-first. CommonJS require may work but import is preferred.
CacheEntry
import type { CacheEntry } from 'graphile-cache'
TypeScript users should import types with 'import type'.
default
import cache from 'graphile-cache'
const cache = require('graphile-cache')
Default export is a function to get a named cache instance.

Shows basic usage of getting a cache instance, setting/getting values with TTL, and clearing the cache.

import { getCache } from 'graphile-cache'; // Get or create a cache instance const cache = getCache(); // Set a value with TTL in seconds cache.set('myKey', { data: 'hello' }, 60); // expires after 60 seconds // Get a value const value = cache.get('myKey'); if (value) { console.log('Cached data:', value); } // Clear all entries cache.clear();
Debug
Known issues
gotchaThe cache is intended for use with PostGraphile v5. Automatic pool cleanup only works when integrated with PostGraphile's pool lifecycle hooks.
fix
Ensure you are using the cache as part of a PostGraphile setup, or manually manage cleanup if used standalone.
affects: >=3.0.0
gotchaCache keys are case-sensitive and should be strings. Non-string keys will be coerced to strings, which may cause unexpected behavior.
fix
Always use string keys explicitly.
affects: >=3.0.0
gotchaThe cache uses an LRU algorithm with a default max size. If the cache exceeds the max, old entries are evicted without warning.
fix
Monitor cache size or configure a larger max size if needed.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: getCache is not a function
Importing as default instead of named export.
fix
import { getCache } from 'graphile-cache'
Error: Cache instance not found
Calling getCache('name') with a name that hasn't been initialized.
fix
Use getCache() without arguments for the default cache, or create a named cache with getCache('myCache').
Upgrade
Version history
3.13.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
graphile-cache — npm install graphile-cache · libregistry