Ticket #1738: cache.diff

File cache.diff, 2.2 KB (added by mir@…, 19 years ago)

fixes wrong imports in cache/init.py

  • django/core/cache/__init__.py

    a b # SQL cache #  
    386386#############
    387387
    388388import base64
    389 from django.core.db import db, DatabaseError
     389from django.db import connection, DatabaseError
    390390from datetime import datetime
    391391
    392392class _DBCache(_Cache):
    class _DBCache(_Cache):  
    406406            self._cull_frequency = 3
    407407
    408408    def get(self, key, default=None):
    409         cursor = db.cursor()
     409        cursor = connection.cursor()
    410410        cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % self._table, [key])
    411411        row = cursor.fetchone()
    412412        if row is None:
    class _DBCache(_Cache):  
    414414        now = datetime.now()
    415415        if row[2] < now:
    416416            cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % self._table, [key])
    417             db.commit()
     417            connection.commit()
    418418            return default
    419419        return pickle.loads(base64.decodestring(row[1]))
    420420
    421421    def set(self, key, value, timeout=None):
    422422        if timeout is None:
    423423            timeout = self.default_timeout
    424         cursor = db.cursor()
     424        cursor = connection.cursor()
    425425        cursor.execute("SELECT COUNT(*) FROM %s" % self._table)
    426426        num = cursor.fetchone()[0]
    427427        now = datetime.now().replace(microsecond=0)
    class _DBCache(_Cache):  
    439439            # To be threadsafe, updates/inserts are allowed to fail silently
    440440            pass
    441441        else:
    442             db.commit()
     442            connection.commit()
    443443
    444444    def delete(self, key):
    445         cursor = db.cursor()
     445        cursor = connection.cursor()
    446446        cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % self._table, [key])
    447         db.commit()
     447        connection.commit()
    448448
    449449    def has_key(self, key):
    450         cursor = db.cursor()
     450        cursor = connection.cursor()
    451451        cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s" % self._table, [key])
    452452        return cursor.fetchone() is not None
    453453
    def get_cache(backend_uri):  
    498498
    499499    return _BACKENDS[scheme](host, params)
    500500
    501 from django.conf.settings import CACHE_BACKEND
    502 cache = get_cache(CACHE_BACKEND)
     501from django.conf import settings
     502cache = get_cache(settings.CACHE_BACKEND)
Back to Top