[z3-checkins] r22125 - z3/sqlos/branch/jinty-connection/src/sqlos
jinty at codespeak.net
jinty at codespeak.net
Fri Jan 13 20:16:02 CET 2006
Author: jinty
Date: Fri Jan 13 20:15:59 2006
New Revision: 22125
Modified:
z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py
Log:
Use one cache per thread, globally. This foxes the last test committed, but is still a bit broken.
Modified: z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py
==============================================================================
--- z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py (original)
+++ z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py Fri Jan 13 20:15:59 2006
@@ -17,22 +17,24 @@
from sqlobject.converters import registerConverter
from sqlobject.mysql import mysqlconnection
from sqlobject.cache import CacheSet
-
from zope.app.rdb.interfaces import DatabaseException
from zope.app.container.interfaces import INameChooser
+from zope.thread import local
from sqlos.interfaces import ISQLObject
from sqlos._transaction import SQLObjectTransactionManager
-# I am not sure it is a good idea to have a single global cache. or if it is
-# thread safe. SQLObject seems to think so. We need some more tests to
-# determine this. As a positive, there is no need to look for all caches to
-# expire the objects when committing a transaction.
-
-# if this is made into a thread local thing, then the expireSQLObject hook needs
+# XXX - if this is made into a thread local thing, then the expireSQLObject hook needs
# to expire the object in all caches of other threads.
-cache = CacheSet() # global cache of sqlobjects
+cache = local() # global cache of sqlobjects, one per thread
+
+def getGlobalPerThreadCache():
+ c = getattr(cache, 'cacheset', None)
+ if c is None:
+ cache.cacheset = CacheSet()
+ c = cache.cacheset
+ return c
class ConnectionAdapter:
@@ -40,11 +42,16 @@
DBAPI.__init__(self)
self._connection = connection
self.autoCommit = None
- self.cache = cache # use a global cache
self.debug = 0
self.supportTransactions = False
self._dm = SQLObjectTransactionManager()
+ def _get_cache(self):
+ return getGlobalPerThreadCache()
+ def _set_cache(self, val):
+ pass # don't let ourselves be overridden
+ cache = property(_get_cache, _set_cache)
+
def makeConnection(self):
return self._connection
More information about the z3-checkins
mailing list