ruby on rails - Etags in Controller -
every rails etag example i've seen has been simple fresh_when method being called last line in controller. i'm trying understand how fresh_when method works controller has resource intensive method calls don't want call in request if page still fresh. example,
class notescontroller < applicationcontroller etag { current_user.try :id } def show @note = note.find(params[:id]) @note.do_some_expenisve_data_manipulation fresh_when(@note) end end will @note.do_some_expensive_data_manipulation called if note hasn't been updated since last time user updated it? if placed line below fresh_when called? thanks!
i feel using stale? easier me understand fresh_when. here example.
if stale?(etag: @note, last_modified: @note.updated_at) respond_to |format| format.html { // expensive work here } end end
Comments
Post a Comment