Registry / database / graphql-hooks-memcache

graphql-hooks-memcache

JSON →
library3.2.0jsnpmunverified

In-memory caching implementation for graphql-hooks, currently at version 3.2.0. The package provides a simple LRU-based cache with configurable size and TTL, designed for use with the graphql-hooks React GraphQL client. It supports server-side rendering by allowing rehydration of cache state via initialState. Key differentiators are its minimal API surface and direct integration with graphql-hooks. The library is actively maintained as part of the nearform/graphql-hooks ecosystem.

npm install graphql-hooks-memcache
INSTALL
IMPORT
SIG · GRAPHQL-HOOKS-MEMC
G
graphql-hooks-memcache
databasejavascriptv3.2.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.

default export
import memCache from 'graphql-hooks-memcache'
import { memCache } from 'graphql-hooks-memcache'
The package exports a single default function. Named import will result in undefined.
type import (if TypeScript)
import type { Cache } from 'graphql-hooks'
import type { MemCache } from 'graphql-hooks-memcache'
Types are exported from graphql-hooks, not from this package. Use graphql-hooks for Cache type.
CommonJS require
const memCache = require('graphql-hooks-memcache')
Package supports both ESM and CommonJS.

Shows how to create a GraphQL client with an in-memory cache using graphql-hooks-memcache, including optional size and ttl options.

import { GraphQLClient } from 'graphql-hooks' import memCache from 'graphql-hooks-memcache' const client = new GraphQLClient({ url: '/graphql', cache: memCache({ size: 100, ttl: 60000 }) }) // After SSR, rehydrate cache: // const cache = memCache({ initialState: window.__GRAPHQL_CACHE__ })
Debug
Known issues
gotchaImporting named export 'memCache' will yield undefined. Package uses default export only.
fix
Use default import: import memCache from 'graphql-hooks-memcache'
affects: >=1.0.0
deprecatedThe `initialState` option in memCache() was removed in v3. Use `getInitialState()` and `useHydrateCache` hook instead.
fix
Use cache.getInitialState() on server and hydrate on client with graphql-hooks' useHydrateCache hook.
affects: >=3.0.0
gotchaCache key must be a string. Passing objects or numbers may cause unexpected behavior.
fix
Serialize keys to string: cache.set(JSON.stringify(key), value)
affects: >=1.0.0
gotchaCache does not support partial invalidation based on query fields; it operates on full query keys.
fix
Use manual cache.delete(key) for specific queries or cache.clear() to reset all.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: memCache is not a function
Attempting to call memCache as a named import: import { memCache } from 'graphql-hooks-memcache'
fix
Use default import: import memCache from 'graphql-hooks-memcache'
Cannot find module 'graphql-hooks-memcache' or its corresponding type declarations.
Missing package install or TypeScript not resolving type definitions.
fix
Run npm install graphql-hooks-memcache. Ensure tsconfig.json includes node_modules types.
Type 'undefined' is not assignable to type 'string' in cache.get(key)
cache.get may return undefined for missing keys. TypeScript strict mode catches this.
fix
Check for undefined: const result = cache.get(key) ?? null
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
graphql-hooks-memcache — npm install graphql-hooks-memcache · libregistry