Ticket #7398: ease-custom-cache-backends-with-documentation.diff

File ease-custom-cache-backends-with-documentation.diff, 2.2 KB (added by lau@…, 16 years ago)

Added documentation in docs/settings.txt

  • django/core/cache/__init__.py

     
    2020from django.core.cache.backends.base import InvalidCacheBackendError
    2121
    2222BACKENDS = {
    23     # 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',
     23    # name for use in settings file --> path to the backend module
     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
     31if hasattr(settings, "CACHE_BACKEND_MODULES"):
     32    BACKENDS.update(settings.CACHE_BACKEND_MODULES)
     33
    3134DEPRECATED_BACKENDS = {
    3235    # deprecated backend --> replacement module
    3336    'simple': 'locmem',
     
    5760    if host.endswith('/'):
    5861        host = host[:-1]
    5962
    60     cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
     63    cache_class = getattr(__import__(BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
    6164    return cache_class(host, params)
    6265
    6366cache = get_cache(settings.CACHE_BACKEND)
  • docs/settings.txt

     
    256256
    257257The cache backend to use. See the `cache docs`_.
    258258
     259CACHE_BACKEND_MODULES
     260---------------------
     261
     262**New in Django development version**
     263
     264Default: Not defined.
     265
     266A dictionary of cache backend import paths, keyed by a string
     267identifier for use in ``CACHE_BACKEND``. These are added to the
     268build-in backends. For example, to define a 'penandpaper' backend,
     269use::
     270
     271    CACHE_BACKEND_MODULES = { 'penandpaper' : 'path.to.penandpaper_backend' }
     272
     273Reference this module in CACHE_BACKEND as ``'penandpaper://'``. Note
     274that build-in backends can be replaced by overwriting them in this
     275variable.
     276
    259277CACHE_MIDDLEWARE_KEY_PREFIX
    260278---------------------------
    261279
Back to Top