Hello,

I have a problem that I don't know how to approach. Here it is:

Suppose I have a mapped class `Article` and I have a mapped class
`Author`. `Article.author` is a relation on `Author` that returns the
author of the `Article`. How do I make `Article.author` to cache the
value in memcached?

The problem is that referring to `Article.author` does an SQL query
each time it is called, but there is really no need to query the
database for author every single time.

This value can be cached in memcached and returned instantly from
memory.

What I can't figure out is how to cache the value of relation in
SQLAlchemy?

I could create another property, like `Article.cached_author` which
would first consult memcached for key `article_<id>_author`, and if
it's not there, call `Article.author`, and store this value value in
memcached.

But I don't want to invent new names for my properties.

Can anyone help me figure out how to use the SQLAlchemy relation
property names and still cache them with memcached?


Thanks, Boda Cydo.

Ps. Some people have said that SQLAlchemy caches the values already,
but that is not true! It caches the value **within a single session**
but I am talking here about tens of sessions using my program
simultaneously.

Pss. Please also don't assume that I have single property
`Article.author`, I have various properties, like `Article.keywords`
that returns a long list of keywords associated with Article. If I
don't cache the values returned by accessing these properties, the
application will soon kill the computer it is running on because of
requesting the same data over and over and over again from the
database.

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

Reply via email to