• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Cache all the things - A guide to caching Drupal

Cache all the things - A guide to caching Drupal



Presented at nwdug on 09/01/13

Presented at nwdug on 09/01/13



Total Views
Views on SlideShare
Embed Views



1 Embed 13

https://twitter.com 13



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.


11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • I'm using http://jingbox.com/five/ for my slideshares
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Cache all the things - A guide to caching Drupal Cache all the things - A guide to caching Drupal Presentation Transcript

    • Cache All The Things
    • About MeMike BellDrupal Developer@mikebell_http://drupal.org/user/189605
    • Exactly what things?erm...everything!
    • No really...Frontend:- HTML- CSS- Images- JavascriptBackend:- PHP- MySQLSo pretty much everything then!
    • Where to start?Ask yourself: Why is my site slow?a) Bad codeb) Bad serverc) Its not!
    • Bad CodeStop.Caching will help... but it wont solve yourbigger issues.There are tools to help - xhprof (not coveredhere)
    • Bad Server?So hows £5.99 a month working out for you?Caching will help... but you still have biggerissues.Scale horizontally/vertically for a quick fix thenwork on additional caching.
    • Its not!I like you!Caching is always a good thing, except whenyou have to debug it...
    • Caching in Drupal- Code Level (cache_get/cache_set)- APC (not covering)- Resource caching (this gets tricky!)- DB Layer- CDNs (related to resource caching)
    • Code LevelDrupal has its own caching api.Module Developers use it!cache_set - store data in Drupals cache tablecache_get - get data from Drupals cache tableYou can even define your own cache tables!
    • Code Level (example)<?phpfunction mymodule_cached_data($reset = FALSE) { global $language; $langcode = $language->language; $data = &drupal_static(__FUNCTION__, NULL, $reset); if (!isset($data)) { if (!$reset && $cache = cache_get("mymodule_cached_data:$langcode") && !empty($cache->data)) { $data = $cache->data; } else { $data = t(This would be an array or string generated using translated strings.); cache_set("mymodule_cached_data:$langcode", $data); } } return $data;}?>(source - http://drupal.org/node/145279)
    • Resource CachingMany different types of resourcesEach can be cached by different toolsExample:- Drupals CSS/JS Cache- Drupals Page Cache- Boost- Varnish
    • Resource CachingDrupal default: CSS/JS and Page(taken from digital006.com - ooppss!)
    • Resource Caching - BoostBoost - http://drupal.org/project/boostStatic caching for all Drupal AssetsAnonymous users onlyIdeal for shared hosting environmentsPotentially the easiest to setup
    • Resource Caching - VarnishApplication AcceleratorLinux OnlyCaches resources based on initial viewAnonymous only - very picky with sessions andcookiesInsanely Powerful
    • Resource Caching - VarnishAdvanced setup - requires additional moduleand VCL for Drupal- http://drupal.org/project/varnishGranular ttls (time to live)Specific resource (image/css) and pageelement! All available through VCL config.
    • Resource Caching - VarnishAnatomy of a varnish hit:HTTP/1.1 200 OKServer: ApacheX-Drupal-Cache: MISSExpires: Sun, 19 Nov 1978 05:00:00 GMTLast-Modified: Tue, 08 Jan 2013 21:20:17 +0000Cache-Control: public, max-age=900ETag: "1357680017-1"Content-Language: enX-Generator: Drupal 7 (http://drupal.org)Link: </node/5468>; rel="shortlink",<http://badgerfakedomain.com/>; rel="canonical"Vary: Accept-EncodingContent-Type: text/html; charset=utf-8Date: Tue, 08 Jan 2013 21:20:22 GMTX-Varnish: 979772308 979772303Age: 3Via: 1.1 varnishConnection: keep-aliveX-Cache: HIT
    • Resource Caching - VarnishCache Stores- RAM- DiskRam - super fast - requires a lot of ramDisk - fast - disk space is rarely an issue
    • Data Caching - memcachedData and Database caching layerCaches cache...(and things!)
    • Data Caching - memcachedExample:Core cache - core cache tables (cache_*)Moved into memcached and shared betweenmultiple instances across multiple serversSimple api makes getting and setting easyDrupal requires - http://drupal.org/project/memcache and pecl extension
    • 3rd Party Caching - AkamaiOne of the biggest caching providersA high chance youve experienced Akamai 4-5times today.Static cache of resourcesContent Distribution Network100+ Edge servers all over the planet
    • 3rd Party Caching - AkamaiCoverage for DDOS attacks- Active monitoring and defenseAdvanced redirection rules through controlpanelIts not cheap!Its also pretty magical.
    • 3rd Party Caching - CloudflareSimilar to AkamaiSmaller scaleEmphasis on security and DDOS protection
    • Content Distribution NetworksCDNs for shortOffload resource handling to external provider- Images- Video- Audio- Large filesSyndicate content around the world
    • Content Distribution NetworkWhy use a CDN?- Content is delivered quicker-- Latency cut downPricing is granular - pay as you go type dealAmazon + Rackspace Cloud Files
    • How does it all fit together? Apache / Mysql / Varnish Nginx memcache Apache / Mysql / Nginx memcache Akamai Load Balancer Apache / Mysql / Nginx memcache Varnish Apache / Mysql / Nginx memcache
    • What happens when it all goeswrong?
    • Caching to the rescueEach layer provides protection3rd Party - shield 99% of anon trafficVarnish - the restAnonymous users should never know your sitehas issues.
    • Debugging TipsConfigure different urls for different platforms- Easier to identify what cache layer has anissueDont be afraid to flush caches- Your backend should be able to cope with itAnalyse headers! Drupal and Varnish provide alot of info
    • Debugging TipsMonitor each layer- Icinga- Pingdom
    • Any Questions?