SlideShare a Scribd company logo
Accelerating Rails 
with edge caching 
Michael May | @ohaimmay | SFRails | 10/16/2014
Accelerating Rails with edge caching
Topic 
• Rails caching best practices 
• Dynamic content/caching 
• Edge caching 
• Edge caching dynamic content with Rails
Rails caching 
• Query/SQL 
• Page/Action (removed from Rails 4 core) 
• Asset 
• Fragment
Rails caching 
config.action_controller.perform_caching = true
Query caching 
• Automagically done by rails when 
perform_caching = true 
• Not cached between requests! 
• Could just store the query result in a variable
Manual Query Caching 
class Product < MyModel 
def self.out_of_stock 
Rails.cache.fetch("out_of_stock", expires_in: 1.hour) do 
Product.where("inventory.quantity = 0") 
end 
end 
end
Asset Caching 
• Serve static assets from a proxy 
• config.serve_static_assets = false 
• Enable Compression* 
• config.assets.compress = true 
• # In Rails 4 
• config.assets.css_compressor = :yui 
• config.assets.js_compressor = :uglifier 
• Asset Digests 
• config.assets.digest = true
mmay.rocks/assets/catzlol-75408509152249b79b818b252da51bc4.
Enable Compression* 
Compress HTML, JSON responses at runtime 
module FastestAppEver 
class Application < Rails::Application 
config.middleware.use Rack::Deflater 
end 
* http://robots.thoughtbot.com/content-compression-with-rack-deflater 
end
Accelerating Rails with edge caching
Accelerating Rails with edge caching
Asset Caching 
• Configure an asset host if needed 
• config.action_controller.asset_host = 
ENV[‘FASTLY_CDN_URL'] 
• Cache-Control like a pro 
• config.static_cache_control = 'public, s-maxage= 
15552000, maxage=2592000'
Cache-Control 
public, s-maxage=15552000, maxage=2592000 
public 
“please cache me” 
maxage=2592000 
“keep me for 30 days” 
s-maxage=15552000 
“PROXIES ONLY! - Keep me for 180 days”
Keepin’ it fresh 
• stale-while-revalidate 
• Serve the current (stale) version for n seconds while it re-fetches the 
latest version in the background 
• Cache-Control: max-age=604800, stale-while-revalidate=86400 
• stale-if-error 
• If the re-fetch fails within n seconds of the response becoming stale, 
serve the cached response 
• Cache-Control: max-age=604800, stale-while-revalidate=86400, stale-if-error= 
259200
The Vary HTTP Header 
• In general, never Vary on anything other than 
Content-Encoding 
• Varying makes it impossible to serve the same 
response more than once and limits caching 
benefits 
• NEVER Vary on User-Agent! 
• There are THOUSANDS of these!
Accelerating Rails with edge caching
Dynamic Content
Dynamic Content 
• Changes are unpredictable! 
• user driven events 
• Can’t just set a Time To Live (TTL)
Dynamic Content 
• Changes are unpredictable! 
• user driven events 
• Can’t just set a Time To Live (TTL) 
• Frequently, but not continuously changing 
• Actually static for short periods of time (we can 
cache static things)!
Dynamic Content Caching 
• Usually don’t 
• Edge Side Includes (ESI) 
• Dynamic Site Acceleration (DSA)
Fragment Caching 
The rails answer to caching dynamic HTML 
# products/index.html.erb 
<% cache(cache_key_for_products) do %> 
<% Product.all.each do |p| %> 
<%= link_to p.name, product_url(p) %> 
<% end %> 
<% end %> 
# products_controller.rb 
def update 
… 
expire_fragment(cache_key_for_products) 
… 
end
Nested Fragment Caching 
<% cache(cache_key_for_products) do %> 
All available products: 
<% Product.all.each do |p| %> 
<% cache(p) do %> 
<%= link_to p.name, product_url(p) %> 
<% end %> 
<% end %> 
<% end %>
Nested Fragment Issues 
• Tedious 
• Comb through (probably terrible) view code 
• Cache keys are weird 
• “A given key should always return the same content.” - DHH 
• products/15-20110218104500 
• “A given key should always return the most up-to-date content.” - Me 
• products/15 
• Hacks around cache limitations 
• Memcache has no wildcard purging!
Nested Fragment Issues 
• Garbage left in the cache 
• Defaults writing to disk 
• Memcached, Redis, etc 
• Probably lives in the same DC as your app server 
• Distributing, replication takes effort 
• What about dynamic API caching? 
• “The caching itself happens in the views based on partials rendering 
the objects in question” 
• Take control over your cached data!
Edge Caching
Edge Caching 
aka content delivery network 
aka CDN
Edge Cache 
• Geographically distributed 
• Highly optimized storage and network 
(nanoseconds count) 
• Move content physically closer to the end-users 
• End goal - DECREASE LATENCY!
Accelerating Rails with edge caching
Accelerating Rails with edge caching
Accelerating Rails with edge caching
Accelerating Rails with edge caching
Accelerating Rails with edge caching
The more content we 
can offload, the better 
performance we get
#cachemoney 
• App servers cost real cash money (not cache 
money) 
• Less requests back to your application server 
• Avoid complex or less efficient strategies 
• Edge Side Includes (ESI) 
• Fragment caching
Edge caching the 
dynamic content
Accelerating Rails with edge caching
Our approach to dynamic 
content 
• Tag content with Surrogate-Key HTTP headers 
• Programmatically purge (~150ms globally) 
• By Surrogate-Key 
• By resource path 
• Real-time analytics and log streaming 
• Optimize the hell out of the pieces of the network we 
can control
Tagging responses 
with Surrogate-Key
class ProductsController < ApplicationController 
# set Cache-Control, strip Set-Cookie 
before_filter :set_cache_control_headers,only [:index,:show] 
def index 
@products = Product.last(10) 
# set Surrogate-Key: products 
set_surrogate_key_header @products.table_key 
respond_with @products 
end 
def show 
@product = Products.find(params[:id]) 
# set Surrogate-Key: product/666 
set_surrogate_key_header @product.record_key 
respond_with @product 
end 
end
class ProductsController < ApplicationController 
# set Cache-Control, strip Set-Cookie 
before_filter :set_cache_control_headers,only [:index,:show] 
def index 
@products = Product.last(10) 
# set Surrogate-Key: products 
set_surrogate_key_header @products.table_key 
respond_with @products 
end 
def show 
@product = Products.find(params[:id]) 
# set Surrogate-Key: product/666 
set_surrogate_key_header @product.record_key 
respond_with @product 
end 
end
class ProductsController < ApplicationController 
# set Cache-Control, strip Set-Cookie 
before_filter :set_cache_control_headers,only [:index,:show] 
def index 
@products = Product.last(10) 
# set Surrogate-Key: products 
set_surrogate_key_header @products.table_key 
respond_with @products 
end 
def show 
@product = Products.find(params[:id]) 
# set Surrogate-Key: product/666 
set_surrogate_key_header @product.record_key 
respond_with @product 
end 
end
Purge on updates
class ProductsController < ApplicationController 
def create 
@product = Product.new(params) 
if @product.save 
# purge Surrogate-Key: products 
@product.purge_all 
render @product 
end 
end 
...
def update 
@product = Product.find(params[:id]) 
if @product.update(params) 
# purge Surrogate-Key: product/666 
@product.purge 
render @product 
end 
end
fastly-rails 
github.com/fastly/fastly-rails
Edge caching in 
practice
Be aware of cookies 
• Nothing with a Set-Cookie header is cached (by 
default) 
• Authentication frameworks/middleware might 
inject Set-Cookie after the rails stack removes it 
• Avoid caching pains by knowing when, where, 
and how you use Set-Cookie
edge scripting
URL Rewriting 
• Apache, nginx, etc support URL Rewriting 
• Filter bad requests 
• Normalize paths
URL Rewrite at the edge 
• Varnish HTTP cache 
• VCL 
• Requests never hit origin!
#winning 
meh 
yay
What can we do better? 
• Add better caching defaults? 
• Cache-Control, stale-while-revalidate, stale-if-error 
• Re-use existing rails cache interfaces for edge 
caching? 
• ActiveSupport::Cache::EdgeStore 
• More fine-grained integration with HTTP accelerators 
like Varnish?
Takeaways 
• Rails has tons of built-in caching options 
• Get fancy with Cache-Control directives 
• Use Google PageSpeed Insights (chrome plugin 
adds it to dev tools) 
• Dynamic edge caching is all about the power of 
purge! 
• Similar school of thought to rails action caching
Questions? 
Contact: Michael May | @ohaimmay | michael@fastly.com 
cool links: 
fastly-rails - github.com/fastly/fastly-rails 
surrogate keys - fastly.com/blog/surrogate-keys-part-1 
cache-control tutorial - docs.fastly.com/guides/tutorials/cache-control-tutorial 
serve stale cache-control - fastly.com/blog/stale-while-revalidate 
vary header best practices - fastly.com/blog/best-practices-for-using-the-vary-header 
caching like & share buttons - fastly.com/blog/caching-like-and-share-buttons 
pagespeed insights - developers.google.com/speed/pagespeed

More Related Content

What's hot (20)

PDF
Improve Magento Performance
Harald Zeitlhofer
 
PDF
Next Generation DevOps in Drupal: DrupalCamp London 2014
Barney Hanlon
 
PDF
Aem dispatcher – tips & tricks
Ashokkumar T A
 
PPT
Configuring Apache Servers for Better Web Perormance
Spark::red
 
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
PPTX
JSR107 Come, Code, Cache, Compute!
Payara
 
KEY
Drupal High Availability High Performance 2012
Amazee Labs
 
PDF
A Tale of 2 Systems
David Newman
 
PPTX
Silverstripe at scale - design & architecture for silverstripe applications
BrettTasker
 
PPTX
Magento performance feat. core Hacks
Daniel Niedergesäß
 
PPTX
Supercharge JavaEE applications using JCache
Payara
 
KEY
Performance and scalability with drupal
Ronan Berder
 
KEY
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
PPTX
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
PPTX
Ansible for large scale deployment
Karthik .P.R
 
PDF
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
DataStax
 
PDF
Ruby Driver Explained: DataStax Webinar May 5th 2015
DataStax
 
PPTX
Performance out
Andrea Martinez
 
PDF
Squeezing Performance out of Hazelcast
Hazelcast
 
PDF
Caching on the web
Jean Carlo Emer
 
Improve Magento Performance
Harald Zeitlhofer
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Barney Hanlon
 
Aem dispatcher – tips & tricks
Ashokkumar T A
 
Configuring Apache Servers for Better Web Perormance
Spark::red
 
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
JSR107 Come, Code, Cache, Compute!
Payara
 
Drupal High Availability High Performance 2012
Amazee Labs
 
A Tale of 2 Systems
David Newman
 
Silverstripe at scale - design & architecture for silverstripe applications
BrettTasker
 
Magento performance feat. core Hacks
Daniel Niedergesäß
 
Supercharge JavaEE applications using JCache
Payara
 
Performance and scalability with drupal
Ronan Berder
 
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
Ansible for large scale deployment
Karthik .P.R
 
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
DataStax
 
Ruby Driver Explained: DataStax Webinar May 5th 2015
DataStax
 
Performance out
Andrea Martinez
 
Squeezing Performance out of Hazelcast
Hazelcast
 
Caching on the web
Jean Carlo Emer
 

Similar to Accelerating Rails with edge caching (20)

PDF
Rails Caching: Secrets From the Edge
Fastly
 
PDF
Rails Caching Secrets from the Edge
Michael May
 
PDF
Caching your rails application
ArrrrCamp
 
PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
Day 7 - Make it Fast
Barry Jones
 
PDF
Advanced Apache Cayenne
WO Community
 
PPTX
Improving Performance on Magento 1*
David Z. Lerner
 
PPTX
In-browser storage and me
Jason Casden
 
PPTX
More Cache for Less Cash (DevLink 2014)
Michael Collier
 
PDF
Play Framework and Activator
Kevin Webber
 
PPTX
06 integrate elasticsearch
Erhwen Kuo
 
PDF
High performance website
Chamnap Chhorn
 
PPTX
Caching in Kentico 11
Christopher Bass
 
PDF
DrupalSouth 2015 - Performance: Not an Afterthought
Nick Santamaria
 
PPTX
Where to save my data, for devs!
SharePoint Saturday New Jersey
 
PDF
Velocity - Edge UG
Phil Pursglove
 
PPTX
How_To_Soup_Up_Your_Farm
Nigel Price
 
KEY
Introduction to memcached
Jurriaan Persyn
 
PDF
Azure appfabric caching intro and tips
Sachin Sancheti - Microsoft Azure Architect
 
PDF
The Need for Speed - EpiCenter 2010
Phil Pursglove
 
Rails Caching: Secrets From the Edge
Fastly
 
Rails Caching Secrets from the Edge
Michael May
 
Caching your rails application
ArrrrCamp
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Day 7 - Make it Fast
Barry Jones
 
Advanced Apache Cayenne
WO Community
 
Improving Performance on Magento 1*
David Z. Lerner
 
In-browser storage and me
Jason Casden
 
More Cache for Less Cash (DevLink 2014)
Michael Collier
 
Play Framework and Activator
Kevin Webber
 
06 integrate elasticsearch
Erhwen Kuo
 
High performance website
Chamnap Chhorn
 
Caching in Kentico 11
Christopher Bass
 
DrupalSouth 2015 - Performance: Not an Afterthought
Nick Santamaria
 
Where to save my data, for devs!
SharePoint Saturday New Jersey
 
Velocity - Edge UG
Phil Pursglove
 
How_To_Soup_Up_Your_Farm
Nigel Price
 
Introduction to memcached
Jurriaan Persyn
 
Azure appfabric caching intro and tips
Sachin Sancheti - Microsoft Azure Architect
 
The Need for Speed - EpiCenter 2010
Phil Pursglove
 
Ad

Recently uploaded (20)

PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Python basic programing language for automation
DanialHabibi2
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
July Patch Tuesday
Ivanti
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Ad

Accelerating Rails with edge caching

  • 1. Accelerating Rails with edge caching Michael May | @ohaimmay | SFRails | 10/16/2014
  • 3. Topic • Rails caching best practices • Dynamic content/caching • Edge caching • Edge caching dynamic content with Rails
  • 4. Rails caching • Query/SQL • Page/Action (removed from Rails 4 core) • Asset • Fragment
  • 6. Query caching • Automagically done by rails when perform_caching = true • Not cached between requests! • Could just store the query result in a variable
  • 7. Manual Query Caching class Product < MyModel def self.out_of_stock Rails.cache.fetch("out_of_stock", expires_in: 1.hour) do Product.where("inventory.quantity = 0") end end end
  • 8. Asset Caching • Serve static assets from a proxy • config.serve_static_assets = false • Enable Compression* • config.assets.compress = true • # In Rails 4 • config.assets.css_compressor = :yui • config.assets.js_compressor = :uglifier • Asset Digests • config.assets.digest = true
  • 10. Enable Compression* Compress HTML, JSON responses at runtime module FastestAppEver class Application < Rails::Application config.middleware.use Rack::Deflater end * http://robots.thoughtbot.com/content-compression-with-rack-deflater end
  • 13. Asset Caching • Configure an asset host if needed • config.action_controller.asset_host = ENV[‘FASTLY_CDN_URL'] • Cache-Control like a pro • config.static_cache_control = 'public, s-maxage= 15552000, maxage=2592000'
  • 14. Cache-Control public, s-maxage=15552000, maxage=2592000 public “please cache me” maxage=2592000 “keep me for 30 days” s-maxage=15552000 “PROXIES ONLY! - Keep me for 180 days”
  • 15. Keepin’ it fresh • stale-while-revalidate • Serve the current (stale) version for n seconds while it re-fetches the latest version in the background • Cache-Control: max-age=604800, stale-while-revalidate=86400 • stale-if-error • If the re-fetch fails within n seconds of the response becoming stale, serve the cached response • Cache-Control: max-age=604800, stale-while-revalidate=86400, stale-if-error= 259200
  • 16. The Vary HTTP Header • In general, never Vary on anything other than Content-Encoding • Varying makes it impossible to serve the same response more than once and limits caching benefits • NEVER Vary on User-Agent! • There are THOUSANDS of these!
  • 19. Dynamic Content • Changes are unpredictable! • user driven events • Can’t just set a Time To Live (TTL)
  • 20. Dynamic Content • Changes are unpredictable! • user driven events • Can’t just set a Time To Live (TTL) • Frequently, but not continuously changing • Actually static for short periods of time (we can cache static things)!
  • 21. Dynamic Content Caching • Usually don’t • Edge Side Includes (ESI) • Dynamic Site Acceleration (DSA)
  • 22. Fragment Caching The rails answer to caching dynamic HTML # products/index.html.erb <% cache(cache_key_for_products) do %> <% Product.all.each do |p| %> <%= link_to p.name, product_url(p) %> <% end %> <% end %> # products_controller.rb def update … expire_fragment(cache_key_for_products) … end
  • 23. Nested Fragment Caching <% cache(cache_key_for_products) do %> All available products: <% Product.all.each do |p| %> <% cache(p) do %> <%= link_to p.name, product_url(p) %> <% end %> <% end %> <% end %>
  • 24. Nested Fragment Issues • Tedious • Comb through (probably terrible) view code • Cache keys are weird • “A given key should always return the same content.” - DHH • products/15-20110218104500 • “A given key should always return the most up-to-date content.” - Me • products/15 • Hacks around cache limitations • Memcache has no wildcard purging!
  • 25. Nested Fragment Issues • Garbage left in the cache • Defaults writing to disk • Memcached, Redis, etc • Probably lives in the same DC as your app server • Distributing, replication takes effort • What about dynamic API caching? • “The caching itself happens in the views based on partials rendering the objects in question” • Take control over your cached data!
  • 27. Edge Caching aka content delivery network aka CDN
  • 28. Edge Cache • Geographically distributed • Highly optimized storage and network (nanoseconds count) • Move content physically closer to the end-users • End goal - DECREASE LATENCY!
  • 34. The more content we can offload, the better performance we get
  • 35. #cachemoney • App servers cost real cash money (not cache money) • Less requests back to your application server • Avoid complex or less efficient strategies • Edge Side Includes (ESI) • Fragment caching
  • 36. Edge caching the dynamic content
  • 38. Our approach to dynamic content • Tag content with Surrogate-Key HTTP headers • Programmatically purge (~150ms globally) • By Surrogate-Key • By resource path • Real-time analytics and log streaming • Optimize the hell out of the pieces of the network we can control
  • 39. Tagging responses with Surrogate-Key
  • 40. class ProductsController < ApplicationController # set Cache-Control, strip Set-Cookie before_filter :set_cache_control_headers,only [:index,:show] def index @products = Product.last(10) # set Surrogate-Key: products set_surrogate_key_header @products.table_key respond_with @products end def show @product = Products.find(params[:id]) # set Surrogate-Key: product/666 set_surrogate_key_header @product.record_key respond_with @product end end
  • 41. class ProductsController < ApplicationController # set Cache-Control, strip Set-Cookie before_filter :set_cache_control_headers,only [:index,:show] def index @products = Product.last(10) # set Surrogate-Key: products set_surrogate_key_header @products.table_key respond_with @products end def show @product = Products.find(params[:id]) # set Surrogate-Key: product/666 set_surrogate_key_header @product.record_key respond_with @product end end
  • 42. class ProductsController < ApplicationController # set Cache-Control, strip Set-Cookie before_filter :set_cache_control_headers,only [:index,:show] def index @products = Product.last(10) # set Surrogate-Key: products set_surrogate_key_header @products.table_key respond_with @products end def show @product = Products.find(params[:id]) # set Surrogate-Key: product/666 set_surrogate_key_header @product.record_key respond_with @product end end
  • 44. class ProductsController < ApplicationController def create @product = Product.new(params) if @product.save # purge Surrogate-Key: products @product.purge_all render @product end end ...
  • 45. def update @product = Product.find(params[:id]) if @product.update(params) # purge Surrogate-Key: product/666 @product.purge render @product end end
  • 47. Edge caching in practice
  • 48. Be aware of cookies • Nothing with a Set-Cookie header is cached (by default) • Authentication frameworks/middleware might inject Set-Cookie after the rails stack removes it • Avoid caching pains by knowing when, where, and how you use Set-Cookie
  • 50. URL Rewriting • Apache, nginx, etc support URL Rewriting • Filter bad requests • Normalize paths
  • 51. URL Rewrite at the edge • Varnish HTTP cache • VCL • Requests never hit origin!
  • 53. What can we do better? • Add better caching defaults? • Cache-Control, stale-while-revalidate, stale-if-error • Re-use existing rails cache interfaces for edge caching? • ActiveSupport::Cache::EdgeStore • More fine-grained integration with HTTP accelerators like Varnish?
  • 54. Takeaways • Rails has tons of built-in caching options • Get fancy with Cache-Control directives • Use Google PageSpeed Insights (chrome plugin adds it to dev tools) • Dynamic edge caching is all about the power of purge! • Similar school of thought to rails action caching
  • 55. Questions? Contact: Michael May | @ohaimmay | [email protected] cool links: fastly-rails - github.com/fastly/fastly-rails surrogate keys - fastly.com/blog/surrogate-keys-part-1 cache-control tutorial - docs.fastly.com/guides/tutorials/cache-control-tutorial serve stale cache-control - fastly.com/blog/stale-while-revalidate vary header best practices - fastly.com/blog/best-practices-for-using-the-vary-header caching like & share buttons - fastly.com/blog/caching-like-and-share-buttons pagespeed insights - developers.google.com/speed/pagespeed