Command
Add Caching
Adds caching to a hot read path with clear keys, an expiry and invalidation on writes, after proving the path is hot.
11. Read the code and its callers. Confirm it is worth caching: estimate how often it is read versus written, and how costly each call is. If it is cheap or write-heavy, say so and stop.
22. Use the cache already in the project. Do not add Redis or a new package without asking.
33. Build the key from every input that changes the result (ids, locale, filters, tenant, user role). Prefix it with a version string so a format change can invalidate everything.
44. Pick a TTL from how stale the data may be, and add jitter so many keys do not expire at once. Protect against a stampede with a lock or request coalescing when the miss is expensive.
55. Invalidate on every write path that changes the source data. List those paths explicitly.
Claude CodeCodex
Add Caching
CommandBackend and APIs
Free