On Wed, 22 Sep 2004 23:19:26 +0200, Olivier Migeon <[EMAIL PROTECTED]> wrote:
> Hi all, this is my first post to this group, after a couple of days
> playing with webware.
>
> I'm creating a page containing a form including a <select> field which
> <options> values are filled from a database query. I would like to
> cache the result of the query, in order to make the query only once,
> and therefore speed up the rendering. I really mean once, not once per
> session.
>
> To the best of my knowledge (correct me if I'm wrong), you can't rely
> on instances variables to store persistent-accross-requests variables :
> the instance may or may be not reused, may or not be cached.
>
> I though that storing the result of my query in a class variable would
> solve the problem, but it doesn't.
> My code looks like this:
>
> class MyPage(SitePage.SitePage):
>
> def getData(self):
> ...
> cur = self.con.cursor()
> cur.execute("select foo, bar from mytable")
> data = cur.fetchall()
> options = ['<option value="%s">%s</option>' % x for x in data]
> self.__class__.data = "<select>%s</select>" % options
>
> def writeHTML(self):
> ...
> if hasattr(self.__class__, "data"):
> # data already stored in a class variable
> pass
> else:
> self.getData()
> ...
> self.write(.... + self.__class__.data + ...)
>
> So, my questions are :
>
> 1) why doesn't it work ? It's not a caching issue because my
> CacheServletClasses is set to 0 in my Application.config file.
>
> 2) what is the best way to make persistent variables accross requests
> and sessions ?
>
> 3) I did some mod_python programming and I used to deal with this issue
> by running a SOAP server alongside the HTTP server, which was holding
> all the persistent data. Is this an option with Webware or is there
> something more clever to do ?
>
> many thanks,
>
> Olivier
If you are only fetching the information once for the entire
application, you can grab it on context init. You would have to then
store the information in a variable in the AppServer object but it
would only be evaluated when you first start the server. Not sure if
this a correct solution to the problem but I've been using it to store
information read from a config file. Look at contextInitialize in
context_name/__init__.py.
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss