Action caching behaves much like page caching except it processes the controller filters. You can also make it conditional as seen in this episode.
# products_controller.rb
cache_sweeper :product_sweeper, :only => [:create, :update, :destroy]
caches_action :index, :cache_path => :index_cache_path.to_proc
#...
private
def index_cache_path
if admin?
'/admin/products'
else
'/public/products'
end
end
# config/environments/development.rb
config.action_controller.perform_caching = true
# config/environment.rb
config.load_paths << "#{RAILS_ROOT}/app/sweepers"
# app/sweepers/product_sweeper.rb
class ProductSweeper < ActionController::Caching::Sweeper
observe Product
def after_save(product)
expire_cache(product)
end
def after_destroy(product)
expire_cache(product)
end
def expire_cache(product)
expire_action '/admin/products'
expire_action '/public/products'
end
end
分享到:
相关推荐
actionpack-action_caching Action Pack的操作缓存(从Rails 4.0的核心中删除)。 安装将此行添加到应用程序的Gemfile中:gem'actionpack-action_caching',然后执行:$ bundle O actionpack-action_caching Action ...
actionpack-page_caching Action Pack的静态页面缓存(从Rails 4.0的核心中删除)。 介绍 页面缓存是一种缓存方法,其中,响应主体存储在Web服务器可以直接提供服务的文件中: 对端点E的请求到达。 计算其响应并...
Amazon Web Services in Action, Second Edition is a comprehensive introduction to computing, storing, and networking in the AWS cloud. Readers will find clear, relevant coverage of all the essential ...
Time for action – configuring layers and layer groups for caching 219 Time for action – using tiles with OpenLayers 221 Time for action – seeding a layer 227 Using an external GeoWebCache 231 ...
It's free, open source, and easy to utilize from most standard programming languages., Redis in Action introduces Redis and walks you through examples that demonstrate how to use it effectively....
Transactions, concurrency, and caching Chapter Six: Advanced mapping concepts Chapter Seven: Retrieving objects efficiently Chapter Eight: Developing NHibernate Applications Chapter Nine:...
又是in Action丛书,2010版的,Chapter 1: Introducing portals and portlets Chapter 2: Portlet lifecycle Chapter 3: Portlet 2.0 API -Portlet objects and container runtime options Chapter 4: Portlet 2.0 ...
Erlang and OTP in Action Martin Logan, Eric Merritt, and Richard Carlsson MEAP Began: August 2008 Softbound print: May 2010 (est.) | 500 pages ISBN: 1933988789 Part One: Getting Past Pure Erlang; ...
Praise for the Third Edition of Spring in Action Preface Acknowledgments About this Book 1. Core Spring Chapter 1. Springing into action 1.1. Simplifying Java development 1.1.1. Unleashing the power ...
Portlets in Action is a comprehensive guide to building portlet-driven applications in Java. It teaches portlet development hands-on as you develop a portal that incorporates most key features of the ...
名称Mojolicious :: Plugin :: Cache-用于缓存的Mojolicious插件版本版本0.0017概要动作缓存: plugin 'cache-action';$self->plugin('cache-action');页面缓存: plugin 'cache-page'$self->plugin('cache-page');...
It is recommended to use another caching library to improve performance. This can be done by passing a [PSR-6](http://www.php-fig.org/psr/psr-6/) compatible library to the client: ```php use League\...
什么事啊 这是一个简单的Rails插件,使用memcache进行操作缓存,并让... 因此,如果s / o登录,他将获得prevent_action_caching cookie集,并且Nginx永远不会传递其请求的内存缓存。 Nginx设置了一个自定义标头-Mem-C
6. 解释Spark中的转换(Transformation)和动作(Action)。 7. Spark支持哪些语言进行数据处理? 8. 什么是Spark的Lineage(血统)? 9. 解释广播变量和累加器。 10. Spark SQL是什么,它有什么优势? 11. 什么是...
Loading images from the internet 212 ■ Displaying images on the billboard 214 ■ Caching the downloaded image for reuse 216 9.4 Posting data to a web server 217 Tracking current weather: sending post...
3. The ActiveMQ In Action Examples ................................................... 59 3.1. Understanding the Example Use Cases ..................................... 59 3.1.1. Prerequisites ..........
skjolber/maven-cache-github-action操作必须在构建作业中出现两次, step: restore和step: save参数: jobs : hello_world_job : runs-on : ubuntu-latest name : Maven build with caching steps : - name :...
As a major revision of the popular Hibernate in Action, it builds on the same single example application to introduce and explain the latest Hibernate 3.2 in detail. In addition, the new and ...