Caching
Use cache policies and cache interceptors to add response caching to NestForge applications.
Feature activation
Section titled “Feature activation”nestforge = { version = "1", features = ["cache", "redis"] }Cache model
Section titled “Cache model”Cache support is built around:
CacheStoreCachePolicyCacheInterceptor
That design makes caching part of the request pipeline instead of a hidden controller behavior.
Define a policy
Section titled “Define a policy”#[derive(Default, Clone)]struct UsersCachePolicy;
impl nestforge::CachePolicy for UsersCachePolicy { type Store = nestforge::InMemoryRedisStore;}Register the interceptor
Section titled “Register the interceptor”NestForgeFactory::<AppModule>::create()? .use_interceptor::<nestforge::CacheInterceptor<UsersCachePolicy>>();Default behavior
Section titled “Default behavior”The built-in defaults are conservative:
- only
GETrequests are cached - request URI is used as the cache key
- only successful
200 OKresponses are stored
Override policy methods when your application needs custom cache keys, TTL behavior, or cacheability rules.