My application use a “conventional” cache sweeper (subclass of ActionController::Caching::Sweeper) to expire the cache (essentially fragments).
Now, the cache expiration locks the application for several seconds, with negative impact on the performance as perceived by the customer.
It would be great to be able to expire the cache asynchronously, eg using delayed_job (the application is currently hosted on heroku).
Unfortunately, simply adding handle_asynchronously to the cache expiration function within the sweeper doesn’t seem to work.
Is it possible to expire cache fragments asynchronously with delayed_job? If so, what are the best practices to do that?
You will need to manually expire the cache. Because you’re using memcached, you just need any data required to generate the cache keys.
You can then write a delayed job to access the cache directly and delete the required keys.
Here’s an example sweeper for Resque: