
它运行正常,缓存模板被创建并从缓存中读取,但问题是,如果我更改模型条目,如更改“标题”,它不会使缓存失效,它仍然显示旧标题.
这是我的jbuilder模板索引:
Json.cache! "news" do |Json| Json.array!(@news) do |news| Json.ID news.ID Json.Title news.Title Json.excerpt news.excerpt Json.content strip_links news.content Json.image news.image Json.source news.source Json.published_at news.published_at Json.created_at news.created_at endend
我正在通过Railsadmin接口更改属性.
解决方法 解决方案是传递@news集合而不是“news”字符串作为缓存键,如:Json.cache! @news do |Json| Json.array!(@news) do |news| Json.ID news.ID Json.Title news.Title Json.excerpt news.excerpt Json.content strip_links news.content Json.image news.image Json.source news.source Json.published_at news.published_at Json.created_at news.created_at endend
当我第一次尝试这个时,我在尝试在磁盘上创建缓存文件时收到错误“filename too long”.这是因为我的@news集合太大(对象太多)所以我改变它以返回更少的对象.对于像memcached这样的东西,这不会有问题,但是当保存到磁盘时,文件名的长度受 *** 作系统的限制.
总结以上是内存溢出为你收集整理的ruby-on-rails – Rails Cache Digest和Jbuilder全部内容,希望文章能够帮你解决ruby-on-rails – Rails Cache Digest和Jbuilder所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)