简体   繁体   中英

How to use 'stale?' in rails with eTAg

I am new to rails. I am trying to use cache and Etag to throw 304 status when the content is not modified.

My controller code is like this:

 def index
    @projects = @current_user.projects
    if stale?(@projects, public: true)
      render json: {"projects" => @current_user.projects.as_json}, status: 200
    end
  end

I am passing strong ETag with If-None-Match header but I am receiving the 200 status all the times irrespective of the If-None-Match header value.

Thanks in advance!

Is it possible you're running this in development, without setting config.perform_caching to true in config/environments/development.rb ? Essentially caching is disabled by default in development, so to be able to play with this functionality, you need to enable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM