packages/adapters/cache-base/README.md
Base class for Ghost cache adapters. A cache adapter backs one of Ghost's internal caches (settings, image sizes, gscan results, ...) with a store of your choice — an in-process map, Redis, Memcached, etc.
See the Ghost adapters documentation for how adapters are configured and loaded.
Install the base class alongside your adapter:
npm install @tryghost/adapter-base-cache
Extend CacheBase and implement every method listed in requiredFns:
get, set, reset, and keys. Each may be synchronous or return a
Promise.
const {CacheBase} = require('@tryghost/adapter-base-cache');
class MyCache extends CacheBase {
constructor(config) {
super();
// `config` is the settings block from your Ghost config (see below)
this.store = new Map();
}
get(key) {
return this.store.get(key);
}
set(key, value) {
this.store.set(key, value);
}
reset() {
this.store.clear();
}
// Deprecated — may be removed in a future version. Returns all cache keys.
keys() {
return [...this.store.keys()];
}
}
module.exports = MyCache;
Place the adapter at content/adapters/cache/MyCache/index.js and activate it
in your Ghost config. active names the adapter; the matching block is passed
to its constructor:
{
"adapters": {
"cache": {
"active": "MyCache",
"MyCache": {}
}
}
}
This is a workspace package in the Ghost monorepo. From the repo root:
pnpm --filter @tryghost/adapter-base-cache build # compile to build/ with tsc (ESM)
pnpm --filter @tryghost/adapter-base-cache test # type-check + unit tests
This package is ESM-only and compiled with tsc (module: nodenext). Relative
imports in src/ must carry an explicit extension; write the real .ts one —
import {x} from './x.ts' — and tsc rewrites it to .js on emit
(rewriteRelativeImportExtensions).
Copyright (c) 2013-2026 Ghost Foundation - Released under the MIT license. Ghost and the Ghost Logo are trademarks of Ghost Foundation Ltd. Please see our trademark policy for info on acceptable usage.