{"id":45037,"library":"graphile-cache","title":"Graphile Cache","description":"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.","status":"active","version":"3.13.0","language":"javascript","source_language":"en","source_url":"https://github.com/constructive-io/constructive","tags":["javascript","postgraphile","graphile","cache","lru","postgresql","constructive","v5","typescript"],"install":[{"cmd":"npm install graphile-cache","lang":"bash","label":"npm"},{"cmd":"yarn add graphile-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphile-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-first. CommonJS require may work but import is preferred.","wrong":"const getCache = require('graphile-cache').getCache","symbol":"getCache","correct":"import { getCache } from 'graphile-cache'"},{"note":"TypeScript users should import types with 'import type'.","symbol":"CacheEntry","correct":"import type { CacheEntry } from 'graphile-cache'"},{"note":"Default export is a function to get a named cache instance.","wrong":"const cache = require('graphile-cache')","symbol":"default","correct":"import cache from 'graphile-cache'"}],"quickstart":{"code":"import { getCache } from 'graphile-cache';\n\n// Get or create a cache instance\nconst cache = getCache();\n\n// Set a value with TTL in seconds\ncache.set('myKey', { data: 'hello' }, 60); // expires after 60 seconds\n\n// Get a value\nconst value = cache.get('myKey');\nif (value) {\n  console.log('Cached data:', value);\n}\n\n// Clear all entries\ncache.clear();","lang":"typescript","description":"Shows basic usage of getting a cache instance, setting/getting values with TTL, and clearing the cache."},"warnings":[{"fix":"Ensure you are using the cache as part of a PostGraphile setup, or manually manage cleanup if used standalone.","message":"The cache is intended for use with PostGraphile v5. Automatic pool cleanup only works when integrated with PostGraphile's pool lifecycle hooks.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Always use string keys explicitly.","message":"Cache keys are case-sensitive and should be strings. Non-string keys will be coerced to strings, which may cause unexpected behavior.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Monitor cache size or configure a larger max size if needed.","message":"The cache uses an LRU algorithm with a default max size. If the cache exceeds the max, old entries are evicted without warning.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'3.13.0':50 'automat':24,64 'cach':2,4,12,34,80,84 'clean':32 'cleanup':66 'compar':75 'connect':38 'construct':60,87 'current':47 'data':43 'databas':37 'design':14 'differenti':63 'ecosystem':71 'entri':35 'focus':67 'general':78 'general-purpos':77 'graphil':1,3,21,70,83 'integr':25 'javascript':81 'key':62 'leak':46 'lifecycl':30 'lru':11,85 'maintain':52 'memori':45 'minim':73 'monorepo':61 'orient':10 'overhead':74 'part':57 'perform':9 'performance-ori':8 'pool':29,65 'postgraphil':18,27,82 'postgresql':86 'prevent':41 'primarili':13 'provid':5 'purpos':79 'regular':55 'releas':40,54 'scope':68 'simpl':7 'stabl':48 'stale':42 'typescript':89 'use':16 'v5':19,88 'version':49 'worker':22","created_at":"2026-06-07T12:53:03.293802+00:00","updated_at":"2026-06-07T12:53:03.293802+00:00","problems":[{"fix":"import { getCache } from 'graphile-cache'","cause":"Importing as default instead of named export.","error":"TypeError: getCache is not a function"},{"fix":"Use getCache() without arguments for the default cache, or create a named cache with getCache('myCache').","cause":"Calling getCache('name') with a name that hasn't been initialized.","error":"Error: Cache instance not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/constructive-io/constructive","github":"https://github.com/constructive-io/constructive","docs":null,"changelog":null,"pypi":null,"npm":"graphile-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}