Tag: 片段缓存

rails 4缓存过期无效

在我的rails应用程序中,我正在尝试使用嵌套缓存,但是当user.profile.full_name更改时,我的缓存键未到期。 因此,当用户更改他/她的名字时, _profile_product.html.erb显示的full_name仍然是旧名称。 我该如何更换钥匙? 型材/ show.html.erb #this is the profile info and the cache key expires properly when @profile.full_name changes ….. #not nested in the previous cache; #products belonging to the profile are listed with this code under the profile info _profile_products.html.erb _profile_product.html.erb #if I change profile name this one won’t change thanks to the […]

rails4缓存命名约定

我有一个rails 4 app。 我必须以某种方式区分不同的缓存键,但不知道命名约定。 第一个例子: 我有一个带index , completed_tasks和incoming_tasks动作的任务模型。 由于分页,A具有相同的实例名称( @tasks )。 目前,缓存键的名称如下所示。 我的问题:1。缓存密钥结构是否足够好? 2.将密钥的各个部分放在数组中的顺序是否重要? 例如[@tasks.map(&:id), @tasks.map(&:updated_at).max, ‘completed-tasks’]优于[‘completed-tasks’, @tasks.map(&:id), @tasks.map(&:updated_at).max] ? completed_tasks.html.erb tasks.html.erb incoming_tasks.html.erb 第二个例子: 我也有russian-doll-caching的命名惯例的问题: products/index.html.erb _product.html.erb …. 这个版本是否足够好,或者我总是应该在外部和内部缓存键数组中放入一些字符串,以避免在其他页面上使用类似命名的缓存键出现问题。 例如,我计划将放在profile#show页面上,这与我的示例中的内部缓存完全相同。 如果密钥必须不同,则rails的约定是将内部缓存键命名为内部?

rails从片段缓存中遗漏了一些部分

我有一个使用pundit gem进行授权的rails 4 app。 如果我像下面的代码那样执行俄语 – 娃娃片段缓存,则用于授权的条件语句也将被缓存,这是不好的,因为编辑/删除按钮应仅适用于post.user 。 解决这个问题的好方法是什么? 我应该将缓存拆分成更小的部分,还是有办法排除缓存的某些部分? 在这种情况下,轨道惯例是什么? index.html.erb _post.html.erb “modal”, ‘data-target’ => “#updatepost_#{post.id}” %> <a href="#" data-toggle="modal" role="button" data-target="#deletepost_”>Delete Post <div class="col-md-12 post-comment-insert-“> <div class="modal fade updatepost" id="updatepost_” tabindex=”-1″ role=”dialog” aria-labelledby=”myModalLabel”> <div class="modal fade" id="deletepost_” tabindex=”-1″ role=”dialog” aria-labelledby=”myModalLabel”> ……