Django

Code

Changeset 8075

Show
Ignore:
Timestamp:
07/25/08 13:51:32 (1 month ago)
Author:
mtredinnick
Message:

Fixed #7398 -- Allow for custom cache-backends to be used.

Based on a patch from Lau Bech Lauritzen and Brenton Simpson.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r8033 r8075  
    237237    Paul Lanier <planier@google.com> 
    238238    Nicola Larosa <nico@teknico.net> 
     239    Lau Bech Lauritzen 
    239240    Rune RÞnde Laursen <runerl@skjoldhoej.dk> 
    240241    Eugene Lazutkin <http://lazutkin.com/blog/> 
     
    342343    Leo Shklovskii 
    343344    jason.sidabras@gmail.com 
     345    Brenton Simpson <http://theillustratedlife.com> 
    344346    Jozko Skrablin <jozko.skrablin@gmail.com> 
    345347    Ben Slavin <benjamin.slavin@gmail.com> 
  • django/trunk/django/core/cache/__init__.py

    r6822 r8075  
    2020from django.core.cache.backends.base import InvalidCacheBackendError 
    2121 
     22# Name for use in settings file --> name of module in "backends" directory. 
     23# Any backend scheme that is not in this dictionary is treated as a Python 
     24# import path to a custom backend. 
    2225BACKENDS = { 
    23     # name for use in settings file --> name of module in "backends" directory 
    2426    'memcached': 'memcached', 
    2527    'locmem': 'locmem', 
     
    4547            (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning) 
    4648        scheme = DEPRECATED_BACKENDS[scheme] 
    47     if scheme not in BACKENDS: 
    48         raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme 
    4949 
    5050    host = rest[2:] 
     
    5858        host = host[:-1] 
    5959 
    60     cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass') 
    61     return cache_class(host, params) 
     60    if scheme in BACKENDS: 
     61        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']) 
     62    else: 
     63        module = __import__(scheme, {}, {}, ['']) 
     64    return getattr(module, 'CacheClass')(host, params) 
    6265 
    6366cache = get_cache(settings.CACHE_BACKEND) 
  • django/trunk/docs/cache.txt

    r7754 r8075  
    77from database queries to template rendering to business logic -- to create the 
    88page that your site's visitor sees. This is a lot more expensive, from a 
    9 processing-overhead perspective, than your standard read-a-file-off-the-filesystem 
    10 server arrangement. 
     9processing-overhead perspective, than your standard 
     10read-a-file-off-the-filesystem server arrangement. 
    1111 
    1212For most Web applications, this overhead isn't a big deal. Most Web 
     
    186186 
    187187    CACHE_BACKEND = 'dummy:///' 
     188 
     189Using a custom cache backend 
     190---------------------------- 
     191 
     192**New in Django development version** 
     193 
     194While Django includes support for a number of cache backends out-of-the-box, 
     195sometimes you will want to use a customised verison or your own backend.  To 
     196use an external cache backend with Django, use a Python import path as the 
     197scheme portion (the part before the initial colon) of the ``CACHE_BACKEND`` 
     198URI, like so:: 
     199 
     200    CACHE_BACKEND = 'path.to.backend://' 
     201 
     202If you're building your own backend, you can use the standard cache backends 
     203as reference implementations. You'll find the code in the 
     204``django/core/cache/backends/`` directory of the Django source. 
     205 
     206Note: Without a really compelling reason, like a host that doesn't support the 
     207them, you should stick to the cache backends included with Django. They've 
     208been really well-tested and are quite easy to use. 
    188209 
    189210CACHE_BACKEND arguments