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
So cache!

•

Keep coding fun

•

Keep users happy
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, b...
Varnish
sub	
  vcl_hit	
  {

	
  	
  if	
  (req.request	
  ==	
  "PURGE")	
  {

	
  	
  	
  	
  purge;

	
  	
  	
  	
  er...
•

Easy to use

•

Configure, don’t code

•

Lightweight
Easy to use
•

Copy original route parameters

•

Note: don’t use getRouteCollection()!

•

$cacheManager

	
  	
  -­‐>inv...
Configure, don’t code
driebit_http_cache:

	
  	
  http_cache:

	
  	
  	
  	
  varnish:

	
  	
  	
  	
  	
  	
  ips:	
  [...
Lightweight
•

Collect all routes that will be invalidated.

•

Send PURGE requests in kernel.terminate.

•

Send them in ...
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....
HTTP cache: keeping it fresh
Upcoming SlideShare
Loading in …5
×

HTTP cache: keeping it fresh

509 views

Published on

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.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
509
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

HTTP cache: keeping it fresh

  1. 1. Keeping it fresh David de Boer
  2. 2. Hello • I’m David • Lead developer at Driebit, Amsterdam • Open source fanatic
  3. 3. The problem • E-learning platform • Now used by ~50% of Dutch primary and secondary schools • Slow
  4. 4. So cache! • Keep coding fun • Keep users happy
  5. 5. Caching models ! • Expiration • Validation • Invalidation
  6. 6. What we had • REST API • Content changes at predictable moments • Rush hour
  7. 7. What we needed • Fresh data at push of button • Talk to Symfony as little as possible
  8. 8. Back to caching models Quick refresh Don’t talk to Symfony Expiration × ✔ Validation ✔ × Invalidation ✔ ✔
  9. 9. “There are only two hard things in Computer Science: cache invalidation and naming things.” – Phil Karlton
  10. 10. “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
  11. 11. Varnish sub  vcl_hit  {
    if  (req.request  ==  "PURGE")  {
        purge;
        error  200  “Purged";
    }
 }
  12. 12. • Easy to use • Configure, don’t code • Lightweight
  13. 13. Easy to use • Copy original route parameters • Note: don’t use getRouteCollection()! • $cacheManager
    -­‐>invalidateRoute('my_route')
    -­‐>flush();
  14. 14. 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

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

×