@boring-stack-pkg/eslint-plugin-cache-keys
v0.1.2
Published
ESLint rules preventing cache-layer bugs: missing TTLs, unprefixed keys that collide on shared Redis, and inline keys that bypass the helper layer.
Maintainers
Readme
eslint-plugin-cache-keys
ESLint rules preventing the most common cache-layer bugs:
cache-set-must-have-ttl— cache writes without a TTL field accumulate forever and OOM Redis.cache-key-must-be-prefixed— cache keys must start with a configured namespace prefix to prevent collisions when multiple apps share a Redis instance.cache-key-from-helper(opt-in) — cache keys must come from a configured helper function. Forces a single source of truth and makes invalidation tractable across a codebase.
The recommended config enables rules 1 and 2 at error. Rule 3 is opt-in
because it requires you to declare your project's key-builder helpers.
Install
pnpm add -D @boring-stack-pkg/eslint-plugin-cache-keysPeer deps: eslint >= 8.57, @typescript-eslint/parser >= 8,
typescript >= 5.
Use (flat config)
import tsParser from "@typescript-eslint/parser";
import cacheKeys from "@boring-stack-pkg/eslint-plugin-cache-keys";
export default [
{
files: ["**/*.{ts,tsx}"],
languageOptions: { parser: tsParser },
plugins: { "cache-keys": cacheKeys },
rules: {
"cache-keys/cache-set-must-have-ttl": "error",
"cache-keys/cache-key-must-be-prefixed": "error",
"cache-keys/cache-key-from-helper": [
"error",
{ helperNames: ["userCacheKey", "stripeEventCacheKey"] },
],
},
},
];Or use the bundled config (rules 1–2 enabled, rule 3 off):
import cacheKeys from "@boring-stack-pkg/eslint-plugin-cache-keys";
export default [cacheKeys.configs.recommended];Rules
| Rule | Description | Default in recommended |
| ------------------------------------------------------------------------ | ---------------------------------------- | ---------------------- |
| cache-set-must-have-ttl | .set calls must include ttlSeconds | error |
| cache-key-must-be-prefixed | Keys must start with a configured prefix | error |
| cache-key-from-helper | Keys must be built by configured helpers | off (opt-in) |
License
MIT.
