简体   繁体   中英

Rails 3: Caching *all* pages from a controller without manually adding them

We have a Rails app that has some pages that are available to all and pages you only see when you are logged. We call them 'public' pages and 'application' pages. Since the public pages don't changes, we want to enable page caching for them. One solution for that would be to manually add

caches_page :index, ..

to all our public controllers. However, I don't find this convenient and Rubyish. All our public controllers inherit from a PublicController class (some shared methods, behavior, ..), so I thought of putting the caching method also in the PublicController so that all public controllers are cached by default (again, public means more or less static content). However there exists no

caches_page :all

in Rails. I thought of using something like

self.new.public_methods(false)

and then iterate through them and add them to caching. But since this is in the PublicController, no actual actions are listed.

Does anyone have a good solution for this problem? Or is the manual way the only way to go.

Thank you!

通过查看caches_page工作方式,您可以添加一个过滤器来做到这一点:

after_filter :cache_page

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