[Zodb-checkins] CVS: StandaloneZODB/ZODB - Connection.py:1.65
Jeremy Hylton
jeremy@zope.com
Sat, 13 Apr 2002 16:17:23 -0400
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv23118
Modified Files:
Connection.py
Log Message:
Use cache.get() instead of has_key() & __getitem__() combo.
=== StandaloneZODB/ZODB/Connection.py 1.64 => 1.65 ===
except: pass
- def __getitem__(self, oid,
- tt=type(())):
- cache=self._cache
- if cache.has_key(oid): return cache[oid]
+ def __getitem__(self, oid, tt=type(())):
+ obj = self._cache.get(oid, None)
+ if obj is not None:
+ return obj
__traceback_info__ = (oid)
p, serial = self._storage.load(oid, self._version)
@@ -144,8 +144,9 @@
object._p_changed=None
object._p_serial=serial
- cache[oid]=object
- if oid=='\0\0\0\0\0\0\0\0': self._root_=object # keep a ref
+ self._cache[oid] = object
+ if oid=='\0\0\0\0\0\0\0\0':
+ self._root_=object # keep a ref
return object
def _persistent_load(self,oid,
@@ -153,13 +154,13 @@
__traceback_info__=oid
- cache=self._cache
-
if type(oid) is tt:
# Quick instance reference. We know all we need to know
# to create the instance wo hitting the db, so go for it!
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:
module, name = klass
@@ -175,11 +176,13 @@
object._p_jar=self
object._p_changed=None
- cache[oid]=object
+ self._cache[oid] = 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]
def _setDB(self, odb):
@@ -219,8 +222,11 @@
else:
self._cache.invalidate(object._p_oid)
- def cacheFullSweep(self, dt=0): self._cache.full_sweep(dt)
- def cacheMinimize(self, dt=0): self._cache.minimize(dt)
+ def cacheFullSweep(self, dt=0):
+ self._cache.full_sweep(dt)
+
+ def cacheMinimize(self, dt=0):
+ self._cache.minimize(dt)
__onCloseCallbacks = None
@@ -426,7 +432,6 @@
self._tmp=None
self._storage=tmp
-
self._cache.invalidate(src._index.keys())
self._invalidate_creating(src._creating)