Rails缓存:过时了吗?在开发中始终返回真实 [英] Rails caching: stale? always returns true in development
问题描述
在我的个人模型中,遵循 hawkins.io :
Following hawkins.io in my person model I have:
def self.cache_key
Digest::MD5.hexdigest "#{maximum(:updated_at)}.try(:to_i)-#{count}"
end
我正在使用Pundit进行授权.因此,在我的人员控制器中,我有:
I am using Pundit for authorization. So in my people controller, I have:
def show
@person = Person.find(params[:id])
if authorize @person
if stale? @person
@person = Person.basic_details.last_details.find(params[:id]).decorate
@person_histories = PersonHistory.new(person_id: @person.id).results
respond_with @person
end
end
end
在我的development.rb环境中:
In my development.rb environment:
config.cache_store = :file_store, Rails.root.join('tmp', 'cache'), { expires_in: 4.hours }
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
(我在Windows上,因此没有memcached等设置).
(I'm on Windows here so don't have memcached etc setup).
当我重新加载人显示视图时,加载它后,我希望它会被完全缓存.但是它会重新查询数据库等.是否有设置或缺少的内容?当我检查缓存键时,它们是相同的,但是陈旧了吗?@person
似乎总是返回true.
When I reload the person show view, immediately after loading it, I would expect it to be fully cached. Yet it requeries the database etc etc. Is there a setting or something I am missing? When I check the cache keys they are the same, but stale? @person
always appears to return true.
推荐答案
您尝试过吗?
禁用Rack :: MiniProfiler缓存
Disable Rack::MiniProfiler caching
Rack :: MiniProfiler中间件将删除与缓存相关的标头,因此,它是陈旧的吗?将始终返回TRUE.我们可以使用以下初始化程序完全禁用缓存:
Rack::MiniProfiler middleware will remove headers related to caching and as such, stale? will ALWAYS RETURN TRUE. We can disable caching altogether using the following initializer:
Rack::MiniProfiler.config.disable_caching = false
这篇关于Rails缓存:过时了吗?在开发中始终返回真实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!