Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Low-level caching


If per-view and template caching don't solve your needs, Django offers you a way to choose exactly the pieces that get cached. The low-level cache API lets you read and write to and from the cache and explicitly decide how you want the data to be cached.

Say, for example, you wanted the press release to show the current date and time each refresh, but you don't want the database to get queried for the content of the release? You can use low-level caching to save the result of the database lookup.

Before we begin, remove the template fragment caching from the previous example by editing the highlighted line in mycompany/templates/press/cache_detail.html:

<html>
<head>
<title>{{ press.title }}</title>
</head>
<body>
<h1>{{ press.title }}</h1>
<p>
<hr>Current Datetime: {% now "H:m:s" %}<hr>
Author: {{ press.author }}<br/>
Date: {{ press.pub_date }}<br/>
</p>
<p>
{{ press.body }}
</p...