I've recently had the opportunity to use Django's caching mechanism and I thought I'd describe the usage here in the hopes it helps someone else.
Caching XML
I have been spending most of my Satchmo development time working on building integration with the UPS online tools. The idea is that you can send an XML message to the UPS servers and you'll get back info on the actual UPS cost to send the package. Because of Satchmo's design and the power of Django's templates, this wasn't actually that hard to do. One problem I did have was that I had to make multiple calls to the UPS servers to get price quotes for all of the options. I'm not a big fan of early optimization but this process was really expensive and caused noticeable delays so I looked for alternatives to be more efficient.
The UPS interface does provide a message to get a list of all valid shipping options. I decided to use that message once, then cache the results. Subsequent calls would then check to make sure the request had stayed the same, then read form cache. Very slick and very efficient. You can see the full implementation here. The basic idea is here:
cache_key_response = "ups-cart-%s-response" % int(cart.id)
cache_key_request = "ups-cart-%s-request" % int(cart.id)
last_request = cache.get(cache_key_request)
if (last_request != request) or cache.get(cache_key_response) is None:
cache.set(cache_key_request, request, 60)
cache.set(cache_key_response, self._process_request(connection, request), 60)
tree = cache.get(cache_key_response)
On a side note, the other thing I like about using Django is that I have access to really simple to use XML tools like Elementtree. When looking at the UPS XML developer notes on how to do XML processing in other languages, I felt so happy that I could use Elementtree.
New Template Tag
A while back, a new cache template tag was added to django. Since Satchmo requires a cache backend, I decided to look at using this tag in some of the templates on this site. The documentation is really simple and the usage is brain dead easy too. Just wrap the cache tag around part of your template, give it a name and expire time and you are good to go. I decided to add this capability on the front page and some of the blog pages where I'm pulling data from the db that rarely changes. The best part about this is that you can control this 100% from your templates so there is no need to change any code. The other great part is that you have really fine grained control of what you do and do not want to cache. Just one more instance of how much thought and good work goes into Django.