Commit af1540ad authored by Jeremy Hylton's avatar Jeremy Hylton

Use cache.get() instead of has_key() & __getitem__() combo.

parent 046da4a8
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
############################################################################## ##############################################################################
"""Database connection support """Database connection support
$Id: Connection.py,v 1.64 2002/03/27 10:14:03 htrd Exp $""" $Id: Connection.py,v 1.65 2002/04/13 20:17:22 jeremy Exp $"""
__version__='$Revision: 1.64 $'[11:-2] __version__='$Revision: 1.65 $'[11:-2]
from cPickleCache import PickleCache, MUCH_RING_CHECKING from cPickleCache import PickleCache, MUCH_RING_CHECKING
from POSException import ConflictError, ReadConflictError from POSException import ConflictError, ReadConflictError
...@@ -107,10 +107,10 @@ class Connection(ExportImport.ExportImport): ...@@ -107,10 +107,10 @@ class Connection(ExportImport.ExportImport):
try: del self.cacheGC try: del self.cacheGC
except: pass except: pass
def __getitem__(self, oid, def __getitem__(self, oid, tt=type(())):
tt=type(())): obj = self._cache.get(oid, None)
cache=self._cache if obj is not None:
if cache.has_key(oid): return cache[oid] return obj
__traceback_info__ = (oid) __traceback_info__ = (oid)
p, serial = self._storage.load(oid, self._version) p, serial = self._storage.load(oid, self._version)
...@@ -144,8 +144,9 @@ class Connection(ExportImport.ExportImport): ...@@ -144,8 +144,9 @@ class Connection(ExportImport.ExportImport):
object._p_changed=None object._p_changed=None
object._p_serial=serial object._p_serial=serial
cache[oid]=object self._cache[oid] = object
if oid=='\0\0\0\0\0\0\0\0': self._root_=object # keep a ref if oid=='\0\0\0\0\0\0\0\0':
self._root_=object # keep a ref
return object return object
def _persistent_load(self,oid, def _persistent_load(self,oid,
...@@ -153,13 +154,13 @@ class Connection(ExportImport.ExportImport): ...@@ -153,13 +154,13 @@ class Connection(ExportImport.ExportImport):
__traceback_info__=oid __traceback_info__=oid
cache=self._cache
if type(oid) is tt: if type(oid) is tt:
# Quick instance reference. We know all we need to know # Quick instance reference. We know all we need to know
# to create the instance wo hitting the db, so go for it! # to create the instance wo hitting the db, so go for it!
oid, klass = oid oid, klass = oid
if cache.has_key(oid): return cache[oid] obj = self._cache.get(oid, None)
if obj is not None:
return obj
if type(klass) is tt: if type(klass) is tt:
module, name = klass module, name = klass
...@@ -175,11 +176,13 @@ class Connection(ExportImport.ExportImport): ...@@ -175,11 +176,13 @@ class Connection(ExportImport.ExportImport):
object._p_jar=self object._p_jar=self
object._p_changed=None object._p_changed=None
cache[oid]=object self._cache[oid] = object
return object return object
if cache.has_key(oid): return cache[oid] obj = self._cache.get(oid, None)
if obj is not None:
return obj
return self[oid] return self[oid]
def _setDB(self, odb): def _setDB(self, odb):
...@@ -219,8 +222,11 @@ class Connection(ExportImport.ExportImport): ...@@ -219,8 +222,11 @@ class Connection(ExportImport.ExportImport):
else: else:
self._cache.invalidate(object._p_oid) self._cache.invalidate(object._p_oid)
def cacheFullSweep(self, dt=0): self._cache.full_sweep(dt) def cacheFullSweep(self, dt=0):
def cacheMinimize(self, dt=0): self._cache.minimize(dt) self._cache.full_sweep(dt)
def cacheMinimize(self, dt=0):
self._cache.minimize(dt)
__onCloseCallbacks = None __onCloseCallbacks = None
...@@ -426,7 +432,6 @@ class Connection(ExportImport.ExportImport): ...@@ -426,7 +432,6 @@ class Connection(ExportImport.ExportImport):
self._tmp=None self._tmp=None
self._storage=tmp self._storage=tmp
self._cache.invalidate(src._index.keys()) self._cache.invalidate(src._index.keys())
self._invalidate_creating(src._creating) self._invalidate_creating(src._creating)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment