Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTTP Cache in Rails 4

HTTP Cache in Rails 4

Talk given during Paris.rb on November 5th, 2013

Christopher Cocchi-Perrier

November 05, 2013
Tweet

Other Decks in Programming

Transcript

  1. ccocchi EPITA MTI 2011 Rails 1.2 rabl-rails, libmemcached_store Scala, JS

    are also fine languages ccocch.io @ccocchi github.com/ccocchi
  2. d e f s h o w e x p

    i r e s _ i n 3 . h o u r s , p u b l i c : t r u e e n d
  3. d e f s h o w f r e

    s h _ w h e n @ p o s t , p u b l i c : t r u e # t h i s w i l l u s e a n M D 5 o f @ p o s t . c a c h e _ k e y e n d d e f s h o w f r e s h _ w h e n e t a g : " m y _ c u s t o m _ t a g " e n d
  4. Marty GET /posts Last-Modified: Tue, 5 Nov 2013 19:45:26 +0000

    GET /posts If-Modified-Since 304 Not Modified Rails
  5. d e f s h o w f r e

    s h _ w h e n @ p o s t , p u b l i c : t r u e # t h i s w i l l u s e @ p o s t . u p d a t e d _ a t e n d d e f s h o w f r e s h _ w h e n l a s t _ m o d i f i e d : [ @ p o s t . u p d a t e d _ a t , @ p o s t . v e r i f i e d _ a t ] . m a x e n d
  6. Are you fresh? d e f s h o w

    i f s t a l e ? ( l a s t _ m o d i f i e d : @ p o s t . p u b l i s h e d _ a t ) # s t a l e ? ( @ p o s t ) # T h i s b l o c k w i l l o n l y b e e x e c u t e d i f t h e r e q u e s t i s n o t f r e s h @ p o s t . s u p e r _ l o n g _ c a l l r e s p o n d _ w i t h @ p o s t e n d e n d
  7. Proxy Rails Marty GET /posts GET /posts max-age + ETag

    max-age=3600 + Etag: "5257d1fa-2a33" Jennifer GET /posts < 3600 max-age + ETag GET /posts GET /posts + ETag From cache 304 Not Modified
  8. Rev. Proxy Rails Marty GET /posts GET /posts max-age=3600 +

    Etag: "5257d1fa-2a33" max-age + ETag Jennifer GET /posts < 3600 max-age=3500 + Etag: "5257d1fa-2a33" GET /posts GET /posts + ETag From cache + max-age + ETag 304 Not Modified
  9. ?