简体   繁体   中英

Rails: Clear page cache without controller

I have set up sweepers to clear specific pages in the page cache when the model is modified via a controller.

How can I use the sweeper from the Rails console (IRB)?

ie. When I modify a model object in the console, either the sweeper should automatically run, or I need a simple way of manually running the sweeper for the modified object.

Take a look at the Rails source for expire_page. It really is just a matter of constructing the cache file's path from the url of the cached page, and then deleting that file. Unfortunately, sweepers are only in the controller layer because you need URL generation (ie url_for), so you'll need to either manually generate the cached page's path yourself or pull in the route generation/recognition to the model layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM