http cache: keeping it fresh
Post on 11-May-2015
219 Views
Preview:
DESCRIPTION
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
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 modelsQuick
refreshDon’t talk
to Symfony
Expiration × ✔
Validation ✔ ×
Invalidation ✔ ✔
– Phil Karlton
“There are only two hard things in Computer Science: cache invalidation and naming things.”
– Symfony2 documentation
“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.”
Varnishsub 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 codedriebit_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
top related