Rails expires fragment cache from models

I am working with a cache in a Rails project and want to expire the cache of a specific URL. I received the following command to expire the fragment corresponding to the passed URL:

ActionController::Base.new.expire_fragment("localhost:3000/users/55-testing-devise/boards/")

I am confused where to put this code in a Rails project so that it runs as soon as the URL is added to the text field and the expiration button is clicked.

+5
source share
3 answers

You should probably consider a different approach. Models do not have to care about how caching works, and traditionally the whole sweeping approach tends to become complex, cumbersome, and incompatible with the rest of the code.

, . -/URL- ( ).

Russian Doll Caching. , , Rails 4 .

, , Rails.

+7

ActionController::Caching::Sweeper - , Rails.

http://api.rubyonrails.org/classes/ActionController/Caching/Sweeping.html

class MyModelSweeper < ActionController::Caching::Sweeper
  observe MyModel

  def after_save(object)
    expire_fragment('...')
  end
end
+3

expire_fragment , , . . DHH : https://github.com/rails/cache_digests/issues/35

I sent a related response about caching a json response: fooobar.com/questions/194461 / ...

+2
source

All Articles