i'm using dogpile to manage caching, and ran into an issue with "assembled 
objects" - in which i (pre)compile a bunch of complex data into the cache 
on first view

an example of the problem i've run into is in the class below... ( it's a 
very simplified illustration )

class CachingApi(object):
    def __init__(self,request,dbSession):
        self.request = request
        self.dbSession = dbSession
        
    def _get_paintings_by_artist_id( self ):
        (artist_id) = self.query_args
        paintings = dbSession.query( model.Paintings ).filter( 
artist_id=artist_id ).all()
        return [ i.as_dict() for i in paintings ]
        
    def get_paintings_by_artist_id( self , artist_id ):
        self.query_args = (artist_id,)
        key = "get_paintings_by_artist_id:%s" % self.query_args
        return utils.regions['object'].get_or_create( key , 
self._get_paintings_by_artist_id )

    def _get_artist_by_id( self ):
        (artist_id) = self.query_args
        artist = dbSession.query( model.Artist ).filter( id=artist_id 
).first()
        if artist :
            artist = artist.as_dict()
        paintings = self.get_paintings_by_artist_id(artist_id)
        stash = ( artist , paintings )
        return stash
        
    def get_artist_by_id( self , artist_id ):
        self.query_args = (artist_id,)
        key = "get_artist_by_id:%s" % self.query_args
        return utils.regions['object'].get_or_create( key , 
self._get_artist_by_id )

( artist , artist_paintings ) = CachingApi( request ,dbSession 
).get_artist_by_id( artist_id )

the issue i've run into, is that the call to get_artist_by_id() creates a 
lock, which keeps get_paintings_by_artist_id() from running.

the workaround i've used is to have multiple caching regions - one for each 
type.

i'm wondering if anyone has ideas on how to restructure this so i don't 
have to do that - or can suggest better ways to handle this sort of 
"recursive" cache.  

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/ZN7nmglMRtsJ.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to