Re: [SQLObject] connection document on wiki
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Charles B. <li...@st...> - 2004-08-31 22:30:29
|
> > 1. Is there a way to manually close a connection? > > Hmm... no. And since SQLObject does pooling it's not trivial. I'm more interested in removing and closing connection objects themselves (i.e. all connections in a specific connection object's pool) vs a single specific connection in a connection object's pool. This would be especially useful when the connection object is only passed into objects when they are fetched (vs defined in the object definition). When I use connection objects this way, they are effectively a pool of one connection used for fetching/updating one object. Granted this is not as efficient as keeping a pool of connections (or a connection per thread) but it is handy for a quick test or rare use situations. (even then it is impractical without a close function though). I'm not sure if looking at this higher level would simplify the problem to a more trival one. My work around is to re-use connections as intended. :) > > 2. Is there a way to manually expire the cache of a connection? > > connection.cache.expireAll() -- that won't removed the cached objects, > but it will only hold weak references. I think cache in "connection.cache.expireAll()" is actually a CacheSet object, and expireAll() is a method of CacheFactory. That lead me to try the following: for key in connection.cache.caches.keys(): connection.cache.caches[key].expireAll() but got: File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site -packages/SQLObject/Cache.py", line 151, in expireAll self.expiredCache[key] = ref(obj) NameError: global name 'obj' is not defined should obj in this case actually be value from the previous line of: for key, value in self.cache.items(): ? I can file a bug report if so. In the mean time I'm giving the method posted by Eddie Corns in July a closer look: http://thread.gmane.org/gmane.comp.python.sqlobject/1630 > > On a more general note I'd be very interested to hear details on how others > > deal with connections in their SQLObject applications, especially > > multi-process applications. > > Yes, that's still a bit of an open issue. It's hard, because it really > depends on how accurate you want to be -- you can be very accurate by > checking each time an attribute is accessed, but that's really > inefficient, and may give you an inconsistent view. I'd be interested > in hearing other people's thoughts as well. My goal with these questions is to end up with an approach that caches fetched data for a specific page request, and then flushes the cache at the end of the request. In practice this might not save much over checking the database each time, but its the best compromise I've come up with so far. Thanks Ian! -Charles. |