summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-09-14 08:37:09 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-09-14 08:37:09 +0000
commit36396fb4307af9764b2f8c53f8f0fcb926be249e (patch)
tree31e3441ed3b72611eb9dd9502d9cf93494d55726 /docs
parentbc216120126be2e792b1e9cf215a4f62b1dfc07c (diff)
Fixed #3766 -- Added in-memory caching for the sites framework. Will speed up all the "current site" lookups. Thanks, Matt Riggott.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6180 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/sites.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/sites.txt b/docs/sites.txt
index e7a8ecbfa6..5896afcf41 100644
--- a/docs/sites.txt
+++ b/docs/sites.txt
@@ -213,6 +213,31 @@ To do this, you can use the sites framework. A simple example::
>>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url())
'http://example.com/mymodel/objects/3/'
+Caching the current ``Site`` object
+===================================
+
+**New in Django development version**
+
+As the current site is stored in the database, each call to
+``Site.objects.get_current()`` could result in a database query. But Django is a
+little cleverer than that: on the first request, the current site is cached, and
+any subsequent call returns the cached data instead of hitting the database.
+
+If for any reason you want to force a database query, you can tell Django to
+clear the cache using ``Site.objects.clear_cache()``::
+
+ # First call; current site fetched from database.
+ current_site = Site.objects.get_current()
+ # ...
+
+ # Second call; current site fetched from cache.
+ current_site = Site.objects.get_current()
+ # ...
+
+ # Force a database query for the third call.
+ Site.objects.clear_cache()
+ current_site = Site.objects.get_current()
+
The ``CurrentSiteManager``
==========================