Reputation: 2735
I have read several blogs on HTTP caching and have tried to implement it in my rails application and its working properly. but the issue is that whenever i modifies my template file(index.erb file) directly then those changes are not appearing on the browser,server is giving me back 304 not modified response.if i edit any of my user from database then only those changes are appearing on the web page.
So i just want to know if there is any way to expire cache and sends 200 response to the user when there is change in template file in http caching.
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
# GET /users.json
def index
@users = User.all
fresh_when etag: @users
end
end
Upvotes: 0
Views: 468
Reputation: 18835
the conditional get aka etag-support in rails is pretty simple. it calculates the etag based on why you pass in. so if you have some kind of counter that you increase when you change the template, the cache-key is expired and the new version will be requested by the browser.
the whole task can be automated by using the git SHA of your deployed app (or some other SCM key). so on every deploy, you are busting the cache. that approach is simple and easy to debug.
Upvotes: 1