I wrote a private method "_select" to cache compiled selects as
attributes of the class instance that is working with the selects.
Example usage is as follows:

>     def _select(self, *args, **kw):
>         """
>         Compiles and caches a select object, returning a reference to it.
>         """
>         attrName = "select-%d" % (hash(repr(args)),)
>         return self.__dict__.setdefault(
>             attrName, select(*args, **kw).compile())

Note that I am using a hash of the string representation of the
arguments tuple as the unique part of the attribute name, not as hash of
the tuple itself. The reason is that the hash chokes on un-hashable
elements of the args tuple.

Any comments on this idea? It seems to work fine, although I don't know
how much it speeds things up.

A working demo (public domain) that you can save as "zoo.py" is at
http://deadbeefbabe.org/paste/2859 for those who want to play. (Maybe
this might be useful as a simple introductory sqlalchemy demo as well?)

- Ed Suominen




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to