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.
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: