• Save
Caching Hypermedia APIs
Upcoming SlideShare
Loading in...5

Caching Hypermedia APIs



Video and slides synchronized, mp3 and slide download available at http://bit.ly/YKORol. ...

Video and slides synchronized, mp3 and slide download available at http://bit.ly/YKORol.

Tim Stokes discusses various URI caching strategies providing real life examples relying on some of the natural behaviors that are built into the HTTP 1.1 protocol. Filmed at qconsf.com.

Tim Stokes is the Applications Architect at FamilySearch.org, a not for profit organization that provides free resources for people to research their family tree. Prior to FamilySearch, Tim worked in London and Sydney with a number of companies including BT, Citigroup, Royal and SunAlliance, Press Co, Prudential, GM Vauxhall, The London Stock Exchange, Qantas, AMP and Intuit Australia.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



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.

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

Caching Hypermedia APIs Caching Hypermedia APIs Presentation Transcript

  • CachingHypermedia APIs By Tim Stokes
  • Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /Caching-Hypermedia-API InfoQ.com: News & Community Site• 750,000 unique visitors/month• Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese)• Post content from our QCon conferences• News 15-20 / week• Articles 3-4 / week• Presentations (videos) 12-15 / week• Interviews 2-3 / week• Books 1 / month
  • Presented at QCon San Francisco www.qconsf.comPurpose of QCon- to empower software development by facilitating the spread ofknowledge and innovationStrategy - practitioner-driven conference designed for YOU: influencers ofchange and innovation in your teams- speakers and topics driving the evolution and innovation- connecting and catalyzing the influencers and innovatorsHighlights- attended by more than 12,000 delegates since 2007- held in 9 cities worldwide
  • A very brief history of HypermediaThe Big Bang, 13.75 Billion Years Ago
  • Various Events…
  • Hypermedia Ted Nelson, 1963
  • HTML HTTPTim Berners-Lee (and friends), 1991
  • REST (HTTP 1.1)Roy Fielding (and his posse), 1999
  • By Paul Downey, http://www.flickr.com/photos/psd/ The Hypermedia Dark Ages, 2000-2005
  • POST /query HTTP/1.1 table=stick&status=thrown The RESTful years, 2005-2009
  • AffordancesMike Amundsen, circa 2010…
  • HTTP withHypermedia +cachability 2012…
  • Choosing a Caching Strategy TheoreticalNatural Managed TTL ETags Other Practical
  • Natural Caching Behavior 1 Transfer state in the body not the URI
  • POST /box/open GET /box
  • POST /boxstate=openGET /box
  • Natural Caching Behavior 2 Un-Safe Requests Invalidate Cache
  • /car8/mycar
  • /car8
  • /car8
  • Natural Caching Behavior 3 Related resources can be Invalidated.
  • POST 1.  /container is invalidated 2.  303 + Location:/container /container/item8 or 2. Content-Location: /container/item8
  • DELETE 1.  /container/item8/container/item8 is invalidated 2. 303 + Location: /container or 2. Content-Location: /container
  • Natural Caching Behavior 4 Beware of Summaries and Bundles
  • GET /lamp/1 1 POST /lamp/1 1 power=onGET /lampslinks… /lamp/1, /lamp/2, /lamp/3, /lamp/4,/lamp/5, /lamp/6, etc…GET /all-on-lamps 5 1 3
  • RESOURCE DESIGN NOTES:•  The URI should not carry state•  Symmetry between state in and out•  One way to get each piece of state•  Beware of Summaries and Bundles
  • Natural Caching Behavior 5 Cached responses can be bound to specific contexts beyond the URI.
  • GET /boxAccept-Language: EN SYSTEM box Cache-Control: max-age=3600 Vary: Accept-LanguageGET /boxAccept-Language: FR boîte Cache-Control: max-age=3600 Vary: Accept-Language
  • Natural Caching Behavior 6 There is no guaranteeyou will see the latest representation
  • Relativity
  • PUT /lampON   OR GET /lamp
  • Managed Caching Behavior 1 Use Etags with conditional GETs
  • GET /dog6 ETag: 6 SYSTEM GET /dog If-None-Match: 6 ✓ 304
  • GET /dog6 ETag: 6 SYSTEM GET /dog If-None-Match: 6 3 200 ETag: 3
  • Managed Caching Behavior 2 Let Caches know about all resourcesthat are invalid in the response to a state change.
  • Mark Nottingham’sLinked Cache Invalidation Drafthttp://tools.ietf.org/html/draft-nottingham-linked-cache-inv-03  
  • Relying on these Caching Behaviors in Practice •  Compliance to HTTP 1.1•  Interpretation of HTTP 1.1•  Implementation variance•  Intermediaries
  • Approach and granularity•  Design the shape of your resources carefully.•  Target TTL in the Agent first for best natural caching invalidation.•  Use, per request, Agent other request header to trigger caching strategies.•  ETags as second level after TTL.
  • What’s Next? HTTP 2.0http://tools.ietf.org/wg/httpbis/charters  
  • The End