Hi Doug,

On 7 July 2010 22:35, writeson wrote:
> I know, I know, I have a lot of questions about caching, I guess the
> documentation I've read, and been pointed to before, hasn't helped me
> understand how to use it or best practices.

I'm not going answer your questions individually, I'm rather going
explain what we cache at my work.

I work for one of the bigger sites in South Africa, so we need to
(obviously) make sure that our application is as fast as possible. So
far, our biggest bottleneck has been our database, so we've been
trying to cache all our database queries.

We've created a central module where we put a bunch of "list"
functions (get a list of users, for example) that query the database,
and then we cache all of those functions. We're using memcache (via
Beaker) for our caching, so it's available to all instances of the
application running across a number of servers.

Our caching looks something like this:

from pylons import cache

def get_users():
    def fetch_users():
        return Session.query(User).all()
    data_cache = cache.get_cache(u'Data')
    return data_cache.get_value(key=u'Users', createfunc=fetch_users,
expiretime=default_timeout)

"default_timeout" is a value that is loaded from config. We have that,
plus, "short_timeout" and "long_timeout". Things that are liable to
change often use the "short_timeout", things that change often but are
not needed to be up-to-date all the time use "default_timeout" and
things that almost never change use the "long_timeout".

With this, we can call "get_users()" from anywhere in our application,
and it will return the cached list of users. It's not very
complicated, doesn't use regions and things, but it works well for us
because it's "behind the scenes" and we don't have to worry about
when, where, regions, etc.

-- 
Raoul Snyman
B.Tech Information Technology (Software Engineering)
E-Mail:   [email protected]
Web:      http://www.saturnlaboratories.co.za/
Blog:      http://blog.saturnlaboratories.co.za/
Mobile:   082 550 3754
Registered Linux User #333298 (http://counter.li.org)

-- 
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.

Reply via email to