1
Launchpadlib automatically decompresses the documents it receives, and
2
caches the responses in a temporary directory.
5
>>> httplib2.debuglevel = 1
7
>>> from launchpadlib.testing.helpers import salgado_with_full_permissions
8
>>> launchpad_with_cache = salgado_with_full_permissions.login()
13
header: Transfer-Encoding: deflate
19
header: Transfer-Encoding: deflate
22
>>> print launchpad_with_cache.projects['firefox'].name
23
send: 'GET /beta/firefox ...
28
The second and subsequent times you request some object, it's likely
29
that launchpadlib will make a conditional HTTP GET request instead of
30
a normal request. The HTTP response code will be 304 instead of 200,
31
and launchpadlib will use the cached representation of the object.
33
>>> print launchpad_with_cache.projects['firefox'].name
34
send: 'GET /beta/firefox ...
39
The default launchpadlib cache directory is a temporary directory
40
that's deleted when the Python process ends. (If the process is
41
killed, the directory will stick around in /tmp.) It's much more
42
efficient to keep a cache directory across multiple uses of
45
You can provide a cache directory name as argument when creating a
46
Launchpad object. This directory will fill up with cached HTTP
47
responses, and since it's a directory you control it will persist
48
across launchpadlib sessions.
51
>>> tempdir = tempfile.mkdtemp()
53
>>> first_launchpad = salgado_with_full_permissions.login(tempdir)
62
>>> print first_launchpad.projects['firefox'].name
63
send: 'GET /beta/firefox ...
68
This will save you a *lot* of time in subsequent sessions, because
69
you'll be able to use cached versions of the initial (very expensive)
72
>>> second_launchpad = salgado_with_full_permissions.login(tempdir)
81
>>> print second_launchpad.projects['firefox'].name
82
send: 'GET /beta/firefox ...
87
Of course, if you ever need to clear the cache directory, you'll have
90
>>> httplib2.debuglevel = 0
92
>>> shutil.rmtree(tempdir)