Brian, Again, thanks for the quick response, very much appreciated. I think the link will get me going in the direction I want in order to cache the data the way I'm thinking. I came up with my own decorator function that had an expire type behavior, which used the session to hold the data, but the beaker cache mechanism looks like a winner to me. I'll post here again with what I find and my results.
Another related question, in your response you mentioned saving an SA object's primary key in the session and then using that to generate the object again. I don't understand what the "win" is doing that? The primary key is readily available (at least the way I'm using it) and it's the query that's expensive. Is there a reason not to store big chunks of data in the session? Thanks for your help! Doug Brian O'Connor wrote: > > Beaker is used for the session as well as caching (has many different > backends, like memcache, memory, file, etc, I'd have to defer you to the > Beaker documetnation on that). > > I'm no expert with pylons, and my code using beaker is actually a little > out > of date, but this example from the pylons site seems to cover what I was > trying to say decently well: > > http://pylonshq.com/docs/en/0.9.7/caching/#using-the-cache-object > > Basically, you want to store your objects primary key in the session, and > then do something like: > > def get_expensive_results_from_sa(): > # get your SA results here > > mycache = cache.get_cache('my_function', type="memory") > results = mycache.get_value(key='some_identifier', createfunc= > get_expensive_results_from_sa, expiretime=3600) > The results will be stored in cache, and created if they expire (and then > subsequently stored in cache). > > I hope this explain it well, let me know if it doesn't. I'm at work and > don't have access to test things like this, but I did something very > similar > where I was building archives of a newspaper from the past 10 years and > was > caching it for some amount of time, and rebuilding it if it had expired. > On Wed, May 12, 2010 at 8:42 AM, writes_on <[email protected]> wrote: > > -- View this message in context: http://pylons-discuss.1595796.n2.nabble.com/session-individual-object-expiration-tp5037707p5041126.html Sent from the pylons-discuss mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
