Added tutorial 5.
authorJosh Roesslein <jroesslein@gmail.com>
Sat, 8 Aug 2009 21:32:52 +0000 (16:32 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Sat, 8 Aug 2009 21:32:52 +0000 (16:32 -0500)
tutorial/t3.py
tutorial/t4.py
tutorial/t5.py [new file with mode: 0644]

index d5c166caeb276c558dcad63aa732596023dca553..954e745e21c552a3f8a71aa0d10843e8d9105ac1 100644 (file)
@@ -14,11 +14,11 @@ models are used...
 A nice feature of Tweepy is that you can extend or even provide
 your own implementations of these models. Tweepy simply just sets
 the attributes and returns back an instance of your model class.
-This makes it easy to intergrate your ORM into Tweepy.
+This makes it easy to integrate your ORM into Tweepy.
 """
 
 """
-First let's create our own implementaion of Status.
+First let's create our own implementation of Status.
 """
 class MyStatus(tweepy.Status):
 
index 1ee052a15ef9f91fe05889316e46d57b475e9616..a59e2eccea898a41ea3b2569402e41cb20fa5046 100644 (file)
@@ -20,7 +20,7 @@ except tweepy.TweepError, e:
 
 """
 TweepError's can be casted to string format which will
-give details as to what wents wrong.
+give details as to what went wrong.
 The main reasons an exception will be raised include:
 
   -HTTP request to twitter failed
diff --git a/tutorial/t5.py b/tutorial/t5.py
new file mode 100644 (file)
index 0000000..0fed0e7
--- /dev/null
@@ -0,0 +1,42 @@
+import tweepy
+
+""" Tutorial 5 -- Cache
+
+Tweepy provides a caching layer for frequently
+requested data. This can help cut down on Twitter API
+requests helping to make your application faster.
+By default caching is disabled in API instances.
+"""
+
+"""
+Let's create a new API instance with caching enabled.
+Currently Tweepy just comes with an in-memory cache which
+we will use for this demo.
+"""
+cached_api = tweepy.API(cache=tweepy.MemoryCache(timeout=120))
+
+"""
+Now we can use this API instance and any request that uses
+'GET' will be cached for 120 seconds. If no timeout is specified
+the default is 60 seconds.
+Here is a demo using our new cached API instance...
+"""
+non_cached_result = cached_api.public_timeline()
+cached_result = cached_api.public_timeline()
+
+"""
+The first request (non_cached_result) will require a trip
+to the Twitter server. The second request (cached_result)
+will be retrieved from the cache saving a trip to Twitter.
+"""
+
+""" Your own cache implementation
+
+If you wish to use your own cache implementation just
+extend the Cache interface class (tweepy/cache.py).
+Then when you create your API instance pass it in.
+"""
+my_api = tweepy.API(cache=MyCache())
+
+""" The End """
+