Ticket #1738: cache.diff
File cache.diff, 2.2 KB (added by , 19 years ago) |
---|
-
django/core/cache/__init__.py
a b # SQL cache # 386 386 ############# 387 387 388 388 import base64 389 from django. core.db import db, DatabaseError389 from django.db import connection, DatabaseError 390 390 from datetime import datetime 391 391 392 392 class _DBCache(_Cache): … … class _DBCache(_Cache): 406 406 self._cull_frequency = 3 407 407 408 408 def get(self, key, default=None): 409 cursor = db.cursor()409 cursor = connection.cursor() 410 410 cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % self._table, [key]) 411 411 row = cursor.fetchone() 412 412 if row is None: … … class _DBCache(_Cache): 414 414 now = datetime.now() 415 415 if row[2] < now: 416 416 cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % self._table, [key]) 417 db.commit()417 connection.commit() 418 418 return default 419 419 return pickle.loads(base64.decodestring(row[1])) 420 420 421 421 def set(self, key, value, timeout=None): 422 422 if timeout is None: 423 423 timeout = self.default_timeout 424 cursor = db.cursor()424 cursor = connection.cursor() 425 425 cursor.execute("SELECT COUNT(*) FROM %s" % self._table) 426 426 num = cursor.fetchone()[0] 427 427 now = datetime.now().replace(microsecond=0) … … class _DBCache(_Cache): 439 439 # To be threadsafe, updates/inserts are allowed to fail silently 440 440 pass 441 441 else: 442 db.commit()442 connection.commit() 443 443 444 444 def delete(self, key): 445 cursor = db.cursor()445 cursor = connection.cursor() 446 446 cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % self._table, [key]) 447 db.commit()447 connection.commit() 448 448 449 449 def has_key(self, key): 450 cursor = db.cursor()450 cursor = connection.cursor() 451 451 cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s" % self._table, [key]) 452 452 return cursor.fetchone() is not None 453 453 … … def get_cache(backend_uri): 498 498 499 499 return _BACKENDS[scheme](host, params) 500 500 501 from django.conf .settings import CACHE_BACKEND502 cache = get_cache( CACHE_BACKEND)501 from django.conf import settings 502 cache = get_cache(settings.CACHE_BACKEND)