Ticket #3445: 3445.diff

File 3445.diff, 10.9 KB (added by Gary Wilson <gary.wilson@…>, 17 years ago)

Moved cache related modules into a cache package

  • django/

    === renamed directory 'django/core/cache' => 'django/cache'
    === renamed file 'django/middleware/cache.py' => 'django/cache/middleware.py'
    old new  
    11from django.conf import settings
    2 from django.core.cache import cache
    3 from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
     2from django.cache import cache
     3from django.cache.utils import get_cache_key, learn_cache_key, patch_response_headers
    44
    55class CacheMiddleware(object):
    66    """
  • django/

    === renamed file 'django/utils/cache.py' => 'django/cache/utils.py'
    old new  
    1313different header content for headers named in "Vary" need to get different
    1414cache keys to prevent delivery of wrong content.
    1515
    16 A example: i18n middleware would need to distinguish caches by the
     16An example: i18n middleware would need to distinguish caches by the
    1717"Accept-language" header.
    1818"""
    1919
    2020import datetime, md5, re
    2121from django.conf import settings
    22 from django.core.cache import cache
     22from django.cache import cache
    2323
    2424cc_delim_re = re.compile(r'\s*,\s*')
    2525
     
    116116        value = request.META.get(header, None)
    117117        if value is not None:
    118118            ctx.update(value)
    119     return 'views.decorators.cache.cache_page.%s.%s.%s' % (key_prefix, request.path, ctx.hexdigest())
     119    return 'cache.decorators.cache_page.%s.%s.%s' % (key_prefix, request.path, ctx.hexdigest())
    120120
    121121def get_cache_key(request, key_prefix=None):
    122122    """
     
    130130    """
    131131    if key_prefix is None:
    132132        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    133     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, request.path)
     133    cache_key = 'cache.decorators.cache_header.%s.%s' % (key_prefix, request.path)
    134134    headerlist = cache.get(cache_key, None)
    135135    if headerlist is not None:
    136136        return _generate_cache_key(request, headerlist, key_prefix)
     
    154154        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    155155    if cache_timeout is None:
    156156        cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    157     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, request.path)
     157    cache_key = 'cache.decorators.cache_header.%s.%s' % (key_prefix, request.path)
    158158    if response.has_header('Vary'):
    159159        headerlist = ['HTTP_'+header.upper().replace('-', '_') for header in vary_delim_re.split(response['Vary'])]
    160160        cache.set(cache_key, headerlist, cache_timeout)
  • django/

    === renamed file 'django/views/decorators/cache.py' => 'django/cache/decorators.py'
    old new  
    1212"""
    1313
    1414from django.utils.decorators import decorator_from_middleware
    15 from django.utils.cache import patch_cache_control, add_never_cache_headers
    16 from django.middleware.cache import CacheMiddleware
     15from django.cache.utils import patch_cache_control, add_never_cache_headers
     16from django.cache.middleware import CacheMiddleware
    1717
    1818cache_page = decorator_from_middleware(CacheMiddleware)
    1919
  • cache/__init__.py

    === modified file 'django/cache/__init__.py'
    old new  
    44This package defines set of cache backends that all conform to a simple API.
    55In a nutshell, a cache is a set of values -- which can be any object that
    66may be pickled -- identified by string keys.  For the complete API, see
    7 the abstract BaseCache class in django.core.cache.backends.base.
     7the abstract BaseCache class in django.cache.backends.base.
    88
    99Client code should not access a cache backend directly; instead it should
    1010either use the "cache" variable made available here, or it should use the
     
    1717
    1818from cgi import parse_qsl
    1919from django.conf import settings
    20 from django.core.cache.backends.base import InvalidCacheBackendError
     20from django.cache.backends.base import InvalidCacheBackendError
    2121
    2222BACKENDS = {
    2323    # name for use in settings file --> name of module in "backends" directory
     
    4848    if host.endswith('/'):
    4949        host = host[:-1]
    5050
    51     cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
     51    cache_class = getattr(__import__('django.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass')
    5252    return cache_class(host, params)
    5353
    5454cache = get_cache(settings.CACHE_BACKEND)
  • cache/backends/db.py

    === modified file 'django/cache/backends/db.py'
    old new  
    11"Database cache backend."
    22
    3 from django.core.cache.backends.base import BaseCache
     3from django.cache.backends.base import BaseCache
    44from django.db import connection, transaction, DatabaseError
    55import base64, time
    66from datetime import datetime
  • cache/backends/dummy.py

    === modified file 'django/cache/backends/dummy.py'
    old new  
    11"Dummy cache backend"
    22
    3 from django.core.cache.backends.base import BaseCache
     3from django.cache.backends.base import BaseCache
    44
    55class CacheClass(BaseCache):
    66    def __init__(self, *args, **kwargs):
  • cache/backends/filebased.py

    === modified file 'django/cache/backends/filebased.py'
    old new  
    11"File-based cache backend"
    22
    3 from django.core.cache.backends.simple import CacheClass as SimpleCacheClass
     3from django.cache.backends.simple import CacheClass as SimpleCacheClass
    44import os, time, urllib
    55try:
    66    import cPickle as pickle
  • cache/backends/locmem.py

    === modified file 'django/cache/backends/locmem.py'
    old new  
    11"Thread-safe in-memory cache backend."
    22
    3 from django.core.cache.backends.simple import CacheClass as SimpleCacheClass
     3from django.cache.backends.simple import CacheClass as SimpleCacheClass
    44from django.utils.synch import RWLock
    55import copy, time
    66
  • cache/backends/memcached.py

    === modified file 'django/cache/backends/memcached.py'
    old new  
    11"Memcached cache backend"
    22
    3 from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
     3from django.cache.backends.base import BaseCache, InvalidCacheBackendError
    44
    55try:
    66    import cmemcache as memcache
  • cache/backends/simple.py

    === modified file 'django/cache/backends/simple.py'
    old new  
    11"Single-process in-memory cache backend."
    22
    3 from django.core.cache.backends.base import BaseCache
     3from django.cache.backends.base import BaseCache
    44import time
    55
    66class CacheClass(BaseCache):
  • django/conf/global_settings.py

    === modified file 'django/conf/global_settings.py'
     
    273273# CACHE #
    274274#########
    275275
    276 # The cache backend to use.  See the docstring in django.core.cache for the
     276# The cache backend to use.  See the docstring in django.cache for the
    277277# possible values.
    278278CACHE_BACKEND = 'simple://'
    279279CACHE_MIDDLEWARE_KEY_PREFIX = ''
  • django/contrib/admin/views/main.py

    === modified file 'django/contrib/admin/views/main.py'
     
    22from django.conf import settings
    33from django.contrib.admin.filterspecs import FilterSpec
    44from django.contrib.admin.views.decorators import staff_member_required
    5 from django.views.decorators.cache import never_cache
     5from django.cache.decorators import never_cache
    66from django.contrib.contenttypes.models import ContentType
    77from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
    88from django.core.paginator import ObjectPaginator, InvalidPage
  • django/contrib/sessions/middleware.py

    === modified file 'django/contrib/sessions/middleware.py'
     
    11from django.conf import settings
    22from django.contrib.sessions.models import Session
    33from django.core.exceptions import SuspiciousOperation
    4 from django.utils.cache import patch_vary_headers
     4from django.cache.utils import patch_vary_headers
    55import datetime
    66
    77TEST_COOKIE_NAME = 'testcookie'
  • django/middleware/gzip.py

    === modified file 'django/middleware/gzip.py'
     
    11import re
    22from django.utils.text import compress_string
    3 from django.utils.cache import patch_vary_headers
     3from django.cache.utils import patch_vary_headers
    44
    55re_accepts_gzip = re.compile(r'\bgzip\b')
    66
  • django/middleware/locale.py

    === modified file 'django/middleware/locale.py'
     
    11"this is the locale selecting middleware that will look at accept headers"
    22
    3 from django.utils.cache import patch_vary_headers
     3from django.cache.utils import patch_vary_headers
    44from django.utils import translation
    55
    66class LocaleMiddleware(object):
  • django/views/decorators/vary.py

    === modified file 'django/views/decorators/vary.py'
     
    1 from django.utils.cache import patch_vary_headers
     1from django.cache.utils import patch_vary_headers
    22
    33def vary_on_headers(*headers):
    44    """
  • docs/cache.txt

    === modified file 'docs/cache.txt'
     
    294294intensive database query. In cases like this, you can use the low-level cache
    295295API to store objects in the cache with any level of granularity you like.
    296296
    297 The cache API is simple. The cache module, ``django.core.cache``, exports a
     297The cache API is simple. The cache module, ``django.cache``, exports a
    298298``cache`` object that's automatically created from the ``CACHE_BACKEND``
    299299setting::
    300300
    301     >>> from django.core.cache import cache
     301    >>> from django.cache import cache
    302302
    303303The basic interface is ``set(key, value, timeout_seconds)`` and ``get(key)``::
    304304
  • tests/regressiontests/cache/tests.py

    === modified file 'tests/regressiontests/cache/tests.py'
     
    11# Unit tests for cache framework
    22# Uses whatever cache backend is set in the test settings file.
    33
    4 from django.core.cache import cache
     4from django.cache import cache
    55import time, unittest
    66
    77# functions/classes for complex data type tests       
Back to Top