Browse files

Merge pull request #11 from seqoy/dev

"Using ETAGs with TTImageView Article" article.
  • Loading branch information...
2 parents dde0dd5 + 226e030 commit 3c6ce26d842d652e95fe518b88a8e596cbfddead @jwang jwang committed Jul 27, 2011
Showing with 49 additions and 0 deletions.
  1. +49 −0 _posts/2011-06-21-Using-ETAGs-with-TTImageView.mdown
@@ -0,0 +1,49 @@
+title: Using ETAGs with TTImageView
+css: grid
+<div class="authors">
+ <div class="author">Author: <a href="">Paulo Oliveira</a></div>
+Using ETAGs with TTImageView
+^TTImageView^ is a network-enabled image view that could asynchronously load one image from a web server, has
+the powerful feature to cache the image locally based on different policies.
+One powerful and well knowed policy is use <a href="">HTML ETAGs</a>.
+But how we can enable ^TTImageView^ to use this policy?
+^TTImageView^ internally use the ^TTURLRequest^ in order to make the server call and retrieve the data. ^TTURLRequest^
+default policy is ^TTURLRequestCachePolicyDefault^. So, we have to change this property to ^TTURLRequestCachePolicyEtag^.
+And how we do that?
+Since Three20 version 1.0.7, ^TTImageView^ pass the control to his <b>delegate</b> before fire the <b>request</b>.
+On this specific moment you can set the <b>requester</b> with the new policy.
+Let's see how we can do that in code:
+First the class that will act as <b>delegate</b> should implement the ^TTImageViewDelegate^ protocol:
+ @interface myTTImageViewDelegate <TTImageViewDelegate>
+ ...
+ @end
+Next you should attach your class as delegate of ^TTImageView^:
+ TTImageView *imageView = [[TTImageView alloc] initWithFrame:someFrame];
+ imageView.delegate = myDelegate;
+And finally implement the <code>imageView:willSendARequest</code> method:
+ - (void)imageView:(TTImageView*)imageView willSendARequest:(TTURLRequest*)requester {
+ // Use ETAgs.
+ requester.cachePolicy = TTURLRequestCachePolicyEtag;
+ }
+That's it, this method will be called everytime just before the ^TTImageView^ ask
+the server for the image.

0 comments on commit 3c6ce26

Please sign in to comment.