`
CaiDeHen
  • 浏览: 90301 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#93 Action Caching

阅读更多
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
分享到:
评论

相关推荐

    Action Pack的操作缓存(从Rails 4.0的核心中删除)-Ruby开发

    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的核心中删除)

    actionpack-page_caching Action Pack的静态页面缓存(从Rails 4.0的核心中删除)。 介绍 页面缓存是一种缓存方法,其中,响应主体存储在Web服务器可以直接提供服务的文件中: 对端点E的请求到达。 计算其响应并...

    manning amazon web services in action 2nd edition

    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 ...

    Geoserver Beginner`s Guide

    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 ...

    Redis in Action

    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....

    NHibernate In Action

    Transactions, concurrency, and caching Chapter Six: Advanced mapping concepts Chapter Seven: Retrieving objects efficiently Chapter Eight: Developing NHibernate Applications Chapter Nine:...

    Portlets in Action

    又是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 MEAP May 2010

    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; ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    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

    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-Caching:Mojolicious缓存插件

    名称Mojolicious :: Plugin :: Cache-用于缓存的Mojolicious插件版本版本0.0017概要动作缓存: plugin 'cache-action';$self-&gt;plugin('cache-action');页面缓存: plugin 'cache-page'$self-&gt;plugin('cache-page');...

    google api php client

    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\...

    action_nginx_mem_cache:一个简单的Rails Action缓存过滤器,用于直接Nginx访问缓存

    什么事啊 这是一个简单的Rails插件,使用memcache进行操作缓存,并让... 因此,如果s / o登录,他将获得prevent_action_caching cookie集,并且Nginx永远不会传递其请求的内存缓存。 Nginx设置了一个自定义标头-Mem-C

    spark面试题整理.pdf

    6. 解释Spark中的转换(Transformation)和动作(Action)。 7. Spark支持哪些语言进行数据处理? 8. 什么是Spark的Lineage(血统)? 9. 解释广播变量和累加器。 10. Spark SQL是什么,它有什么优势? 11. 什么是...

    Unity.in.Action.Multiplatform.Game.Development.in.Csharp

    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...

    《activmq in action 》

    3. The ActiveMQ In Action Examples ................................................... 59 3.1. Understanding the Example Use Cases ..................................... 59 3.1.1. Prerequisites ..........

    maven-cache-github-action-beta

    skjolber/maven-cache-github-action操作必须在构建作业中出现两次, step: restore和step: save参数: jobs : hello_world_job : runs-on : ubuntu-latest name : Maven build with caching steps : - name :...

    java persistence with hibernate

    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 ...

Global site tag (gtag.js) - Google Analytics