我正在尝试在我的应用程序中实现片段缓存。它显示大量很少更改的数据,因此我认为片段缓存将是解决我遇到的一些性能问题的最佳解决方案。
我正在使用 Rail 的内置片段缓存和缓存清理器,但我似乎找不到任何测试片段创建/过期的好方法(使用 rspec 和朋友)。
任何帮助将不胜感激。
说明:我真正想要测试的是相应的片段是否已过期,而不是任何特定的内容进入或从缓存中出来。
I'm attempting to implement fragment caching in my application. It displays a lot of data that rarely changes so I figured that fragment caching would be the best solution for some performance problems I've been having.
I'm using Rail's built-in fragment caching and cache sweepers, but I can't seem to find any good way of testing the creation/expiration of the fragments (using rspec and friends).
Any help would be much appreciated.
Clarification: All I really want to test is that the appropriate fragments are expired, not that anything in particular is going in or coming out of the cache.
发布评论
评论(1)
对于 mocha 来说,情况会是这样的:
我们在这个测试中唯一关心的是该方法实际上是用适当的参数调用的,而不是该方法是否确实完成了工作。
在 rspec 中使用:
With mocha it would be something like this:
The only thing we care about with this test is that the method actually gets called with the appropriate arguments not if the method actually does the job.
Used in rspec: