Ticket #3766: sites_docs.2.diff

File sites_docs.2.diff, 1.3 KB (added by Matt Riggott, 8 years ago)

Formatting changes to the docs diff: lines wrapped at 80 characters and a "New in Django development version" notice added.

  • django/trunk/docs/sites.txt

     
    213213    >>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url())
    214214    'http://example.com/mymodel/objects/3/'
    215215
     216Caching the current ``Site`` object
     217===================================
     218
     219**New in Django development version**
     220
     221As the current site is stored in the database, each call to
     222``Site.objects.get_current()`` could result in a database query. But Django is a
     223little cleverer than that: on the first request, the current site is cached, and
     224any subsequent call returns the cached data instead of hitting the database.
     225
     226If for any reason you want to force a database query, you can tell Django to
     227clear the cache using ``Site.objects.clear_cache()``::
     228
     229    # First call; current site fetched from database.
     230    current_site = Site.objects.get_current()
     231    # ...
     232
     233    # Second call; current site fetched from cache.
     234    current_site = Site.objects.get_current()
     235    # ...
     236
     237    # Force a database query for the third call.
     238    Site.objects.clear_cache()
     239    current_site = Site.objects.get_current()
     240
    216241The ``CurrentSiteManager``
    217242==========================
    218243
Back to Top