Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 缓存包含动态内容的静态html的最佳方法是什么?_Ruby On Rails_Caching_Russian Doll Caching - Fatal编程技术网

Ruby on rails 缓存包含动态内容的静态html的最佳方法是什么?

Ruby on rails 缓存包含动态内容的静态html的最佳方法是什么?,ruby-on-rails,caching,russian-doll-caching,Ruby On Rails,Caching,Russian Doll Caching,我在rails中使用haml和俄罗斯玩偶缓存。我的目标是缓存尽可能多的静态html,并且只呈现动态内容。但是,由于中间有一小部分动态代码,所以我经常有一大块未经处理的HTML。 假设此视图包含两个部分: show.html.haml = render 'message' .nested .divs = render 'dynamic' = complex_stuff .something = more_complex_stuff \u container.html.haml

我在rails中使用haml和俄罗斯玩偶缓存。我的目标是缓存尽可能多的静态html,并且只呈现动态内容。但是,由于中间有一小部分动态代码,所以我经常有一大块未经处理的HTML。

假设此视图包含两个部分:

show.html.haml

= render 'message'
.nested
  .divs
    = render 'dynamic'
= complex_stuff
.something
  = more_complex_stuff
\u container.html.haml

= render 'message'
.nested
  .divs
    = render 'dynamic'
= complex_stuff
.something
  = more_complex_stuff
\u dynamic.html.haml

= render 'message'
.nested
  .divs
    = render 'dynamic'
= complex_stuff
.something
  = more_complex_stuff
我无法将
\u容器
部分包装在缓存块中,因为它包含动态内容。我知道我可以根据动态部分中的因变量为缓存块设置关键帧,但是假设动态部分的复杂性太高,无法缓存


解决这个问题的好方法是什么

我写了一个gem来解决这个问题:


您应该运行一些基准测试,以检查这是否确实给您带来了任何好处;我怀疑这会有帮助。缓存纯静态内容没有什么好处(可能会有什么损失),我怀疑对
sub
的额外调用会影响性能。这一点很好。在早期测试中,我的渲染速度提高了15-20%。这当然取决于你能缓存多少html。事实上,缓存静态html内容可以获得巨大的收益,这就是我这么做的原因。我可以看到,如果你有一组更复杂的嵌套部分,你可以从缓存中获益,因为你可以用缓存查找替换对
render
的多次调用。我猜这就是你真正的系统?问题中的示例可能过于简单,无法从中受益,因为缓存的内容(在
\u container.html.haml
中)根本不使用
渲染,它只是静态内容。