Rails expire_page does not delete cached file

I have a controller action that has page caching, and I made a sweeper that calls expire_page with the controller and the specified action ...

The controller action displays the js.erb template, so I'm trying to ensure that expire_page deletes the .js file in public / javascripts, which it does not.

class JavascriptsController < ApplicationController caches_page :lol def lol @lol = Lol.all end end class LolSweeper < ActionController::Caching::Sweeper observe Lol def after_create(lol) puts "lol!!!!!!!" expire_page(:controller => "javascripts", :action => "lol", :format => 'js') end end 

... So, I visit javascripts / lol.js and I get my template. I checked that public / javascripts / lol.js exists ... Then I create a new Lol entry and I see "lol !!!!!!!!!" which means after_create observer method, but expire_page does nothing ...

+6
source share
1 answer

According to RailsGuides: "Page caching ignores all options." I think I had a similar problem when cashing answers .xml : I would write a cache for / /lol.xml , but tried to expire the cache for operations /lol ( write and expire ), which can be seen on the server log). How I did it: I made the "format-agnostic" cache as follows:

 cashes_page :lol, :cache_path => Proc.new { |controller| controller.params.delete_if {|k,v| k == "format"} } 

and expires in a sweeper, like this:

 expire_page(:controller => "javascripts", :action => "lol") 

He solved my problem. Also, as a note, should your lol action be called lols ? Good luck.

+2
source

Source: https://habr.com/ru/post/899657/


All Articles