Re: Threadlocals? Globals?

2012-03-14 Thread Jonathan Vanasco
Depending on what Alice is - and how you plan on scaling your
application - I would either store the object in Beaker ( perhaps with
memcached ) or serialize the underlying data into a no-sql store like
Riak or Mongo.

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Threadlocals? Globals?

2012-03-13 Thread Mike Orr
On Tue, Mar 13, 2012 at 8:39 AM, Theron Luhn the...@madebypanthr.com wrote:
 In my application, the first path segment represents a specific object.  If
 the URL is domain.com/alice/context/view/, traversal will put the
 alice object into request.

 The number of users such as alice will be very small relative to pageviews,
 so it seems it would be better to keep the objects loaded in memory rather
 than pulling one from the disk for every request.  What is the best way to
 do this?  Python discourages globals, and Pyramid discourages thread locals.
  Is one of those the best way, or is there something else I'm unaware of?

You can put a cache in the settings dict, or look into memcached or
Beaker caching. Settings is the appropriate place for application
globals. You can also look at Beaker caching, which has options for
expiration and such.

If you put a SQLAlchemy ORM object into the cache, call
DBSession.expunge() on it first to detach it from the session, Later
if you want to use it to modify the database, you'll have to reattach
it with DBSession.add() or DBSession.merge() -- see the manual for the
difference between the two.

-- 
Mike Orr sluggos...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.