You should consider using a fast key-value store to store pickled user
information objects. Memcached for one has lots of python libraries. Query
the store and do something like `user_info=pickle.loads(value)` whenever a
page is loaded. That should be a lot quicker than instantiating an ORM each
request.

-Dan

On Mon, Nov 23, 2009 at 5:03 PM, Jacob Lyles <[email protected]> wrote:

>
> Hello,
>
> I'm building a small application using web.py with sqlAlchemy. My
> application has users. When a user successfully authenticates, I store
> his user ID in the session.user_id variable. Then I query the database
> every time I want to render a template using the user's information.
> However, this seems wasteful. I've already queried the DB once and
> retrieved a "User" sqlalchemy object instance, is there any place I
> can store this object without having to recreate it every time I GET a
> new page? I tried storing this in a session.user_data variable, but
> that caused errors.
>
> Also, every time I query the database I am creating another sqlAlchemy
> DB engine and another DB session. Is there a way to share a DB engine
> across classes?
>
> So, for instance, I have an URL called '/map' that is linked off the
> home page. In the GET method of the MAP class, I am creating a new
> sqlAlchemy engine, connecting to it to query for user data, doing the
> same for other data, etc. It is the same for all my other URLs.
>
>
> Thanks,
> Jacob
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to