`
CaiDeHen
  • 浏览: 94294 次
  • 性别: 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的请求到达。 计算其响应并...

    elastic search in action

    - **缓存(Caching)**:利用缓存来加速频繁查询的响应速度。 - **索引优化(Index Optimization)**:通过调整索引设置来提高搜索效率。 #### 结语 《Elasticsearch in Action》不仅是一本技术手册,更是学习Elastic...

    Ruby-ActionPack的Action缓存在Rails40中从核心移除

    Page Cache(也称为Action Controller Caching)将整个页面的HTML直接缓存到静态文件系统中,这样服务器可以像处理静态HTML文件一样直接返回,无需经过Rails应用。这种方法简单而高效,但不适用于动态内容,因为所有...

    Apache_Spark源码走读

    Caching Management - **定义**:缓存管理,指的是Spark为提高性能而对RDD中间结果进行缓存的机制。 - **策略**:默认情况下优先使用内存缓存,当内存不足时,会溢出到磁盘缓存。缓存策略可以通过设置参数进行调整...

    Manning Ibatis In Action Jan 2007 Ebook-Bbl.pdf

    - **Improving performance with caching (利用缓存提高性能)**: 第九章详细介绍了如何使用iBATIS的缓存机制来提高应用程序的性能。缓存可以显著减少对数据库的访问次数,从而提高系统的响应速度。 ### 九、数据...

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

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

    Lucene in Action 2nd Edition 英文版

    - **缓存策略(Caching Strategies)**:减少磁盘访问次数,提高查询速度。 - **索引压缩(Index Compression)**:减小索引大小,提高加载速度。 - **分布式搜索(Distributed Search)**:通过多个服务器节点分散负载...

    ASP.NET MVC in Action

    This includes using membership providers, caching mechanisms, and session management. 9. **AJAX Integration:** - **AJAX Support:** The authors explain how to integrate AJAX into ASP.NET MVC ...

    Xcode_Build_Setting_Reference

    Precompiled headers are used to speed up the compilation process by caching the results of preprocessing common header files. ##### SKIP_INSTALL This setting controls whether the built product ...

    Manning Zend Framework in Action

    Caching: Making it Faster** - **缓存技术**:介绍多种缓存技术,包括内存缓存和文件缓存。 - **缓存策略**:探讨如何制定有效的缓存策略,以提高应用程序的性能。 **14. Internationalization and Localization...

    Hibernate In Action中文版

    8. Caching缓存机制:讨论了第二级缓存和查询缓存,以及如何配置和使用第三方缓存提供商,如Ehcache,以提升性能。 9. 高级主题:涵盖了多对一、一对多、多对多的关联映射,以及集合类型如Set、List、Map的使用。还...

    asp.net mvc in action

    15. **缓存(Caching)**:ASP.NET MVC支持多种缓存策略,如Output Cache、Action Filter等,可以显著提高性能。 通过阅读"ASP.NET MVC in Action"这本书,开发者可以深入了解这些概念,并学习如何在实际项目中有效地...

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

    Ajax in Action

    - Caching strategies for efficient data retrieval. - Minimizing JavaScript and CSS file sizes. #### Part IV: Ajax by Example **Chapter 9: Dynamic Double Combo** - **Description**: This chapter ...

Global site tag (gtag.js) - Google Analytics