On Jul 5, 2006, at 12:34 PM, Michael Carter wrote:

> Greetings,
>
> I am working on a way for my app to cache my sqlalchemy objects  
> externally, specifically in memcached. I'm in the thinking and  
> proof of concept stage and I thought I'd ask the list for some wisdom.
>
> Right now I move objects back into the session from the cache using  
> the session._attach function. Is this unwise? merge doesn't work  
> because it hits the database thus defeating the purpose of the cache.
>

_attach is not a public function.  you want save_or_update (or  just  
update() if theyre all detached).  follow the code from update()- 
 >_update_impl()->_register_(dirty|clean)()->_attach() to see all  
extra things you get from that.

> Next, how should I handle relations? I was considering implementing  
> my own list objects that would be cached seperately from the base  
> objects. They would just be a list of ids, and when you ask for a  
> particular one, the list would go check the cache and fallback to  
> the db and return the resulting object.

normally, i would cache whatever relations are loaded on the object  
just the way they are.  otherwise you have to cache SQL queries  
directly since you cant really predict the full SQL/corresponding  
result set that is used to load a relation.   you might also want to  
just build into get() somehow, which wouldnt prevent a lazy-loading  
query from firing off in all cases but would prevent the object  
creation step.

the whole thing might also be accomplished as a subclass of Session  
since you can control object scoping completely at that level, and  
you could also stick a straight up SQL cache in there as well since  
mapper goes through Session to get the connection its working with.    
ive usually been more comfortable with caching SQL directly for  
things like this, often turns out to be easier in the end.



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to