150 likes | 307 Views
REST & Caching. Scaling like the internets. HTTP and REST. REST is an architectural style Draws and relies heavily on HTTP HTTP just scales. HTTP and Caching. Conditional GET Caching intermediaries Web Server Caching Data Caching. SOAP.
E N D
REST & Caching Scaling like the internets
HTTP and REST • REST is an architectural style • Draws and relies heavily on HTTP • HTTP just scales
HTTP and Caching • Conditional GET • Caching intermediaries • Web Server Caching • Data Caching SOAP Because SOAP uses POST and POST is unsafe to cache *Except Data Caching
Server-side Caching • HttpContext.Current.Cache • Velocity • IIS kernel and user mode caching
DEMO IIS Caching
Conditional GET (304 Not Modified) • This may be the most important status code of them all • This one of the ways the web scales • REST piggybacks on this • Saves bandwidth, as well as processing power on both server and client • Works like this • Server sends resource • Headers include “extra” information • Client asks for resource again (GET) • Sends the “extra” information (condition) • If request meets condition, server returns 304 • If request doesn’t, server returns the resource again
Last Modified • One way to implement conditional GET • Server sets Last-Modified header with timestamp • Client uses If-Modified-Since header value • If resource hasn’t changed, server returns a 304
ETag • Another way to implement conditional GET • Server sets an opaque value for the ETag header • Generally implementation is to take a hash value of some or all of the bytes of the resource • Client sends If-None-Match header
Generating ETag ETag is opaque to user agent: meaningful to service string GenerateETag(User u) { byte[] bytes = Encoding.UTF8.GetBytes(u.UserId + u.LastModified.ToString()); byte[] hash = MD5.Create().ComputeHash(bytes); string etag = Convert.ToBase64String(hash); return etag; } void SetETag(string etag) { OutgoingWebResponseContext ctx = WebOperationContext.Current.OutgoingResponse; ctx.ETag = etag; }
DEMO Conditional GET
Summary • REST is an architectural style for building client-server applications • REST relies on HTTP • HTTP scales because of caching
References • HTTP http://www.w3.org/Protocols/ • Conditional GET http://ftp.ics.uci.edu/pub/websoft/caching.html • ETags http://bitworking.org/news/150/REST-Tip-Deep-etags-give-you-more-benefits • REST Starter Kit - HttpClient
Please Complete an Evaluation FormYour feedback is important! • Evaluation forms can be found on each chair • Temp Staff at the back of the room have additional evaluation form copies
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.