Forum: Ruby on Rails caching: fresh_when unless dev

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fbb39261c7f118504731798b2632d8a1?d=identicon&s=25 Igor Abramov (igreh)
on 2014-12-25 17:45
Is there any way to disable HTTP caching when in DEV?


The best I figured out for now is overriding fresh_when method like
this:

def fresh_when
    super(yield) unless ENV['RAILS_ENV'] == 'development'
  end

and in controllers it looks:

fresh_when do
      max_created_at = Time.now # for instance
      {last_modified: max_created_at.utc, etag:
Digest::MD5.hexdigest(max_created_at.to_s)}
    end

PS Sorry but I couldn't find the way to define code block here
This topic is locked and can not be replied to.