Everyone should be using low level caching in Rails
Low levelcaching is very easy to get started with in Rails 3, but it seems to be missingfrom the official guides.I personally use it all the time to help reduce the number of queries or APIcalls I’m making. Heroku has a pretty goodexplanationwhich, if you’re so far unfamiliar with low-levelcaching, is a good place to start.
Whyshould you use low level caching, and what should you use it for? Maybe youhave some data which you need regularly over multiple pages, e.g. a list ofcategories for your blog. You might want to display them on every page butthey’re not going to need to be entirely up to date for every request. Youcould stick this in controllers/application_controller.rb:
Ifyou haven’t used this style. of caching before, note that I’m calling .all on the Categoryquery. In Rails 3 ActiveRecord now uses lazy loading; it doesn’t perform. thequery until you try to use it. This is great for fragment caching in your viewsas it will prevent that query being called if a fragment cache already exists.However, if you’re using low level caching you’ll want to perform. that queryimmediately so that the results, rather than just the query object you’vebuilt, are stored in the cache.
Themainstay of low level caching in Rails is Rails.cache.fetch. There’s something you need toknow before you end up in a spiral of frustration; by defaultthis will cache in your development environment. Toremedy this, add this line to your config/environments/development.rb:
CODE:
config.cache_store = :null_store來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-730272/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- GHD Hair Straighteners a low levelAI
- 記一次kafka的high level和low levelKafka
- Unity Low-level Native Plugin InterfaceUnityPlugin
- Elasticsearch Java Low Level REST Client(初始化)ElasticsearchJavaRESTclient
- Elasticsearch Java Low Level REST Client(執行請求)ElasticsearchJavaRESTclient
- PostgreSQL DBA(71) - Locks(Table-Level):What You Should KnowSQL
- PostgreSQL DBA(74) - Locks(Row-Level):What You Should KnowSQL
- Fast Bokeh Effects Using Low-Rank Linear FiltersASTFilter
- 創新工場王嘉平開講:low-level的計算機視覺計算機視覺
- 論文翻譯:2021_Low-Delay Speech Enhancement Using Perceptually Motivated Target and Loss
- Low-Code,一定“low”嗎?
- DDD for everyone - Google 幻燈片Go
- [論文][半監督語義分割]Semi-Supervised Semantic Segmentation with High- and Low-level ConsistencySegmentation
- 詳細解析rand()%(high-low+1)+low
- Is low code the future of development? Talking about low-code platformsdevPlatform
- MKNetworkKit Auto Caching
- Granting and Managing Item Level Permission using SharePoint2013 Designer Workflow
- asp.net core 系列之Response caching 之 Distributed caching(3)ASP.NET
- [Rails學習之路]Rails路由配置AI路由
- TextInput should be given height
- What database aspects should be monitored?Database
- win10系統everyone怎麼授權_win10系統everyone如何獲得許可權Win10
- 精簡版的Rails框架->Rails::APIAI框架API
- tarjan演算法 更新方式;探討low[u]=min(low[u],low[v]);和low[u]=min(low[u],dfn[v]) 寫得都對 https://www.acwing.com/blog/content/6015/演算法HTTP
- 分散式監控系統Zabbix-3.0.3-完整安裝記錄(3)-監控nginx,php,memcache,Low-level discovery磁碟IO分散式NginxPHP
- 【棧】RailsAI
- Level Up
- Ruby on Rails 生成指定版本的 Rails 專案AI
- rails on ruby,ruby on rails 之程式碼塊(二)AI
- How to Determine When an Index Should be Rebuilt?IndexUI
- The ITer should learn more about ITIL
- Why Startups Should Not Choose NoSQLSQL
- [ERROR]XX is marked as crashed and should be repairedErrorAI
- AI For Everyone?深度分析機器學習雲服務哪家強AI機器學習
- authentication plugin caching_sha2Plugin
- 從Rails到Clojure再到Java,最後回到RailsAIJava
- 痞子衡嵌入式:深扒IAR啟動函式流程及其__low_level_init設計對函式重定向的影響函式
- Rails Security (上)AI