HTTP cache: keeping it fresh
Upcoming SlideShare
Loading in...5
×
 

HTTP cache: keeping it fresh

on

  • 265 views

HTTP caching solutions such as Varnish are great for improving web application performance. Filling up the cache is easy, but how do you get rid of cache entries when they become stale? There are ...

HTTP caching solutions such as Varnish are great for improving web application performance. Filling up the cache is easy, but how do you get rid of cache entries when they become stale? There are three ways: expiration, validation and invalidation. The first two are nice and simple, but have their limitations. The other option, invalidation, is frowned upon for its complexity. Still, it can be very useful. Case in point: an e-learning web platform we built that serves a large number of Dutch pupils and their teachers. I will tell you why and how we added an invalidation scheme to this platform. I will also show you our lightweight Symfony bundle that makes cache invalidation a little less complex.

Statistics

Views

Total Views
265
Views on SlideShare
264
Embed Views
1

Actions

Likes
0
Downloads
4
Comments
0

1 Embed 1

https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

HTTP cache: keeping it fresh HTTP cache: keeping it fresh Presentation Transcript

  • Keeping it fresh David de Boer
  • Hello • I’m David • Lead developer at Driebit, Amsterdam • Open source fanatic
  • The problem • E-learning platform • Now used by ~50% of Dutch primary and secondary schools • Slow View slide
  • So cache! • Keep coding fun • Keep users happy View slide
  • Caching models ! • Expiration • Validation • Invalidation
  • What we had • REST API • Content changes at predictable moments • Rush hour
  • What we needed • Fresh data at push of button • Talk to Symfony as little as possible
  • Back to caching models Quick refresh Don’t talk to Symfony Expiration × ✔ Validation ✔ × Invalidation ✔ ✔
  • “There are only two hard things in Computer Science: cache invalidation and naming things.” – Phil Karlton
  • “You should never need to invalidate 
 cached data…” “Actually, all reverse proxies provide ways 
 to purge cached data, but you should 
 avoid them as much as possible.” – Symfony2 documentation
  • Varnish sub  vcl_hit  {
    if  (req.request  ==  "PURGE")  {
        purge;
        error  200  “Purged";
    }
 }
  • • Easy to use • Configure, don’t code • Lightweight
  • Easy to use • Copy original route parameters • Note: don’t use getRouteCollection()! • $cacheManager
    -­‐>invalidateRoute('my_route')
    -­‐>flush();
  • Configure, don’t code driebit_http_cache:
    http_cache:
        varnish:
            ips:  [127.0.0.1,  123.123.123.1]
            host:  yourapp.nl      invalidators:
        exam_create:
            origin_routes:  [  exams_post  ]
            invalidate_routes:
                exam_get_collection:  ~  #  /exams
        exam_change:
            origin_routes:  [  exam_put,  exam_del  ]
            invalidate_routes:
     exam_get_collection:  ~    #  /exams
                exam_get:  ~                          #  /exams/{id}
                current_exam:  ~                  #  /exams/current

  • Lightweight • Collect all routes that will be invalidated. • Send PURGE requests in kernel.terminate. • Send them in parallel.
  • Christmas wish list • Cache tags (X-­‐Id:  123) • Annotations (Expression Language) • Message queues
  • Thanks! • david@driebit.nl / @ddeboer_nl • driebit/http-cache-bundle • https://github.com/driebit • https://github.com/ddeboer • http://driebit.nl