SuperAPI AI 工具集

caching-strategies

智能体与模型

查看项目

更新于 10-15 20:34

技能介绍

用途:为 Rails 8 应用实现多层缓存以优化性能,适用于添加片段缓存、俄罗斯套娃缓存、低级缓存与 HTTP 缓存等场景。

主要能力:HTTP 缓存使用 ETags 与 fresh_when 返回 304 Not Modified,支持组合 ETag 与 stale? 处理 JSON;片段缓存缓存视图局部;俄罗斯套娃缓存通过 touch: true 实现嵌套片段自动失效;集合缓存用 cached: true 高效渲染集合;低级缓存用 Rails.cache.fetch 缓存任意数据,支持 expires_in 与 race_condition_ttl;Solid Cache 为 Rails 8 默认的数据库后端缓存,无需 Redis。

缓存存储:开发用 :memory_store,生产用 :solid_cache_store(Rails 8 默认)或 :redis_cache_store,测试用 :null_store。生产配置 config.cache_store = :solid_cache_store,开发配置 config.cache_store = :memory_store,开发环境启用缓存用 bin/rails dev:cache。

失效与预热:基于键的自动失效依赖 updated_at;touch 级联更新父级时间戳;可手动删除缓存键或使用 Sweeper 模式;计数器缓存用 counter_cache: true;缓存预热通过后台任务调用统计方法。

测试:提供 with_caching 辅助方法、touch 级联测试、HTTP 缓存 304 测试与缓存失效测试示例。

限制:资料未提供具体性能数据、版本兼容范围或价格信息。