Rails caching: stale? always returns true in development

本秂侑毒 提交于 2019-12-25 05:37:30

问题


Following hawkins.io in my person model I have:

def self.cache_key
   Digest::MD5.hexdigest "#{maximum(:updated_at)}.try(:to_i)-#{count}"
end

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

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

(I'm on Windows here so don't have memcached etc setup).

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.


回答1:


Have you tried this?

Disable Rack::MiniProfiler caching

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


来源:https://stackoverflow.com/questions/35585261/rails-caching-stale-always-returns-true-in-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!