Ticket #7398: importable-backends.diff

File importable-backends.diff, 4.2 KB (added by theillustratedlife, 16 years ago)

Allows CACHE_BACKEND to be a path - doc formatting corrected

  • docs/cache.txt

     
    182182various places but a development/test environment on which you don't want to
    183183cache. As a result, your development environment won't use caching and your
    184184production environment still will. To activate dummy caching, set
    185 ``CACHE_BACKEND`` like so::
     185``CACHE_BACKEND`` like so:
    186186
    187187    CACHE_BACKEND = 'dummy:///'
    188188
     189Using your own cache backend
     190----------------------------
     191
     192**New in Django development version**
     193
     194While Django includes support for many cache backends out-of-the-box, sometimes
     195that just isn't enough.  Consider, for instance, Google App Engine.  Google
     196will host your Django for you, but to maintain a safe and stable platform, it
     197replaces a few common modules like memcached and PIL with its own variants. 
     198Fear not; Django makes it easy to include third-party backends in case the
     199included ones just won't cut the mustard.  All you need to do is supply the
     200full Python path to the backend in the ``CACHE_BACKEND`` setting, like so:
     201
     202    CACHE_BACKEND = 'path.to.cache_backend:///'
     203
     204Make sure, of course, that ``path.to.cache_backend`` is a valid Django backend.  If
     205you're building your own backend, you can use the baked-in cache backends as
     206reference.  You'll find them at ``django.core.cache.backends``.
     207
     208Note: Without a really compelling reason, like a host that doesn't support the
     209them, you should stick to the ones included with Django.  They've been really
     210well-tested and are quite easy to use.
     211
    189212CACHE_BACKEND arguments
    190213-----------------------
    191214
  • AUTHORS

     
    227227    Stuart Langridge <http://www.kryogenix.org/>
    228228    Paul Lanier <planier@google.com>
    229229    Nicola Larosa <nico@teknico.net>
     230    Lau Bech Lauritzen
    230231    Rune Rønde Laursen <runerl@skjoldhoej.dk>
    231232    Eugene Lazutkin <http://lazutkin.com/blog/>
    232233    lcordier@point45.com
     
    323324    Pete Shinners <pete@shinners.org>
    324325    Leo Shklovskii
    325326    jason.sidabras@gmail.com
     327    Brenton Simpson <http://theillustratedlife.com>
    326328    Jozko Skrablin <jozko.skrablin@gmail.com>
    327329    Ben Slavin <benjamin.slavin@gmail.com>
    328330    SmileyChris <smileychris@gmail.com>
  • django/core/cache/__init__.py

     
    2121
    2222BACKENDS = {
    2323    # name for use in settings file --> name of module in "backends" directory
    24     'memcached': 'memcached',
    25     'locmem': 'locmem',
    26     'file': 'filebased',
    27     'db': 'db',
    28     'dummy': 'dummy',
     24    'memcached': 'django.core.cache.backends.memcached',
     25    'locmem': 'django.core.cache.backends.locmem',
     26    'file': 'django.core.cache.backends.filebased',
     27    'db': 'django.core.cache.backends.db',
     28    'dummy': 'django.core.cache.backends.dummy',
    2929}
    3030
    3131DEPRECATED_BACKENDS = {
     
    4444        warnings.warn("'%s' backend is deprecated. Use '%s' instead." %
    4545            (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning)
    4646        scheme = DEPRECATED_BACKENDS[scheme]
    47     if scheme not in BACKENDS:
    48         raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme
    4947
    5048    host = rest[2:]
    5149    qpos = rest.find('?')
     
    5654        params = {}
    5755    if host.endswith('/'):
    5856        host = host[:-1]
    59 
    60     cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
     57       
     58    backend_path = scheme
     59    if scheme in BACKENDS:
     60        backend_path = BACKENDS[scheme]
     61    try:
     62        backend_import = __import__(backend_path, {}, {}, [''])
     63    except ImportError:
     64        raise InvalidCacheBackendError, "Cache backend "+backend_path+" cannot be found."       
     65   
     66    cache_class = getattr(backend_import, 'CacheClass')
    6167    return cache_class(host, params)
    6268
Back to Top