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

Thanks. I thought save_or_update did something else, but it is what I want.
 

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.

Which get do you think should I build into?
 

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.


Are you suggesting hashing the sql queries and using them as keys to store the result sets would be the best way to go about this, as opposed to caching individual objects and relations.


As for the subclassing Session, is this the sort of thing you had in mind?

class CacheSession(Session):
    def get(self, class_, ident, **kwargs):
        try:
            return self.session._get(ident)
        except KeyError:
            pass       
        cache_hash = cache_hashkey(class_, ident)       
        obj = self.cache.get(cache_hash)
        if obj:
            self.cache.set(cache_hash, obj)
            return obj       
        return Session.get(self, class_, ident, **kwargs)

If this is what you were suggesting, then the tricky part would be expiring objects when they are updated. It seems I'd have to get into the uow.flush function or perhaps loop through session.dirty and expire all those objects from the cache after calling uow.flush.


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