2

We use dalli gem w/memcached. The following code caches Foo objects paginated across multiple pages. We are able to cache Foo(s) when we are in a certain page (say 2 or 10 or 15). But when I modify a Foo in page 15 (say Foo-150), we clear the cache for all the objects using the method in FooSweeper. after_save method is being called when the above action happens, but the cache is not getting cleared for all pages and reflects the older values for the requested page.

Is there any mistake in the code snippet given below.

My controller looks like this..

class FooController 

...
  caches_action :index, cache_path: proc { |c| c.params.except(:_).merge(format: request.format) }

...

My sweeper code looks like this..

class FooSweeper < ActionController::Caching::Sweeper
  observe :foo

  def after_save(foo)
    expire_cache(foo)
  end

  def before_destroy(foo)
    expire_cache(foo)
  end

  def expire_cache(foo)
    expire_action(:controller => 'foos', :action => 'index')
    expire_action(:controller => 'foos', :action => 'index', :format => 'text/html')
  end
end
Mano
  • 979
  • 1
  • 18
  • 36

1 Answers1

0

Your controller is calles Foo, but you call controller: 'foos' from your sweeper. It could be the reason why your cache is not properly cleared.

You can fix this by changing foos to foo.

basgys
  • 4,320
  • 28
  • 39