Cache
Introduction
JCC Express MVC ships with a Laravel-style cache API in jcc-express-mvc/lib/Cache.
Core capabilities:
- Multiple stores (
memory,redis) - Key/value operations (
get,put,forget,has) - Batch operations (
many,putMany) - Numeric ops (
increment,decrement) - Helpers (
remember,rememberForever,pull,add) - Tag-based invalidation (
tags([...]).flush())
Bootstrapping cache
Cache is a singleton (Cache.getInstance(...)). You must provide config on first initialization:
TypeScript
After first boot, use Cache.getInstance() anywhere in the same process.
Basic operations
TypeScript
Remember helpers
TypeScript
remember only runs the callback when the key is missing.
Numeric and atomic-style helpers
TypeScript
Batch operations
TypeScript
Tagged cache
Tagged keys are namespaced and can be flushed by tag group:
TypeScript
Store selection
Use the default store or explicitly pick one:
TypeScript
Driver notes
memoryis process-local (fast, reset on restart).redisserializes payloads as JSON and supports TTL withsetEx.- Invalid inputs throw explicit errors (missing key, null value, invalid TTL, etc.).
Summary
- Initialize once with
Cache.getInstance(config). - Use
get/put/rememberfor common read-through caching. - Use
tags(...)when invalidation needs grouping. - Prefer
redisfor shared cache across processes/instances.
