On Mon, Apr 17, 2006 at 09:27:07AM -0500, Jeff Rush wrote:
>  > Specifically, we're using the connection in a
> > non-persistent shopping cart object.  Upon initialization the cart object
> > retrieves the connection from a persistent parent in the context in which
> > the cart is initialized. In this way, different shopping cart items can be
> > stored in different databases depending upon the container.  The parent is
> > essentially a copy of ISQLScript. 
> I copied SQLScript as well.  Be sure that on each SQL operation you re-fetch 
> the connection object using the connection name.  Do not hold on to the 
> connection object itself, as it may change during system re-configuration.
> Here is my calling method:
>      def invoke_SQL(self, query):
>          cache = getCacheForObject(self)
>          location = getLocationForCache(self)
>          if cache and location:
>              _marker = object()
>              result = cache.query(location, {'query': query}, default=_marker)
>              if result is not _marker:
>                  return result
>          try:
>              connection = zapi.getUtility(IZopeDatabaseAdapter,
>                                           self.connection_name)()
>          except KeyError:
>              raise AttributeError, (
>                  "The database connection '%s' cannot be found." % (
>                  self.connection_name))
>          result = queryForResults(connection, query)
>          if cache and location:
>              cache.set(result, location, {'query': query})
>          return result
> Notice the zapi.getUtility() call to re-fetch each time.

At one point in sqlos development we were re-fetching the connection
every time to get local utilities working. That turned out to have a
noticeable performance penalty, i.e. people noticed and started to

So these days we have a per thread cache that is cleaned out before
traversing a site and at the end of every request. 

Brian Sutherland

Metropolis - "it's the first movie with a robot. And she's a woman.
              And she's EVIL!!"
Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to