Author
vzmind-itself
View
2.017
Download
7
Embed Size (px)
DESCRIPTION
A brief overview of caching technics using Rails
2. Vzmind aka Ruby on Rails creator
3. Why caching ?
Culture Pub
Almost 20 000 Vidos
2 000 000 pages viewed
https://github.com/thinkdry/blank-application
4. Cache is everywhere
5. Rails cachingkeyworld: 6. Pages 7. Action 8. Fragment 9.
Sweepersconfig.action_controller.perform_caching = true
app/config/environments/production.rb
Proxy
(Squid, Varnish)
Web Server
(Apache, Nginx)
Rails Stack
(Rack,App)
DB (PostgreSQL, MySQL)
Browser
Cache as earlier as youcan
10. Pages caching
11. Easy to implement but monotlithic and limited 12.
Storedinside the File System
onlyconfig.action_controller.page_cache_directory = RAILS_ROOT +
/
config/environment.rb
class Articles # Add cache on articles index page
caches_page :index
app/controllers/articles_controller.rb
Proxy
Web Server
Rails Stack
DB
Browser
public/cache/articles.html
13. Action caching
14. Easy to implement 15. Carefulwithfilters (Action cachingis
an aroundfilteritself) 16. Carefulwith cache path 17. Chooseyour
Cache Storeconfig.action_controller.cache_store = :file_store,
RAILS_ROOT + /public/cache
config/environment.rb
class Articles caches_action :show,
:cache_path => Proc.new{ |controller|
if controller.request.mobile_device?
controller.params.merge(:mobile=>controller.request.mobile_device?)
else
controller.params
end}
app/controllers/articles_controller.rb
expire_action :action => :show
App/sweepers/article_sweeper.rb
Proxy
Web Server
Rails Stack
DB
Browser
public/cache/articles.html
18. Fragment caching
19. Atomiccaching (result/string/object) 20. Chooseyour
CacheStore- cache(:action => list', :action_suffix =>
'all_articles) do
= All articles:
[email protected] do|article|
=article.title
app/views/articles/index.haml.html
expire_fragment(:controller => articles', :action => list',
:action_suffix => 'all_articles')
app/sweepers/article_sweeper.rb
Proxy
Web Server
Rails Stack
DB
Browser
public/cache/articles.html
21. Overview of Cache Stores
22. Default memory storage 23. Store everything (even object) 24. Not thread safe 25. ActiveSupport::Cache::FileStore 26. Just for my HTML output 27. Old school 28. Simple 29. ActiveSupport::Cache::MemCacheStore 30. Most popularmemory cache store 31. Multi servers 32. Time-basedexpiry support