You do not ever pass the arguments to "get_data_callback."  You need to do
something more like:

class MC():
   @staticmethod
   def get( key, get_data_callback, **kwargs):
       data_set = memcache.get( key )
       if data_set == None:
           data_set = get_data_callback(**kwargs)
           memcache.set( key, data_set )
       return data_set

and:

def get_user( id ):
   return MC.get( key, lambda id: DB.get_user( id ),id=id )


Good luck.

Robert


On Mon, Sep 7, 2009 at 4:25 PM, (jpgerek) <[email protected]> wrote:

>
> Hi, I'm new with python and I having problems to implement the typical
> memcache pattern.
>
> I wan't to make a decorator of the most common memcache pattern so I
> don't have to implement the logic everytime. My intention is having a
> function that receives the key to get and a callback with the
> datastore gets, in case the memcache key expires, it's evicted or
> whatever.
>
> This is what I have now:
>
> class MC():
>    @staticmethod
>    def get( key, get_data_callback ):
>        data_set = memcache.get( key )
>        if data_set == None:
>            data_set = get_data_callback()
>            memcache.set( key, data_set )
>        return data_set
>
> I'm having problems with the callback when some params are required.
> For instance:
>
> class DB():
>    @staticmethod
>    def get_user( id ):
>          return User().all().filter('id =', id').fetch(1)
>
> def get_user( id ):
>    return MC.get( key, lambda id: DB.get_user( id ) )
>
> The error I get when I call 'get_user(1)' is something like:
>
> TypeError: <lambda>() takes exactly 1 argument (0 given)
>
> Though it works in this case:
>
> def get_user_one():
>     return User().all().filter('id = 1').fetch(1)
>
> It seems to be something with the params, they are lost, could it be
> solved with closures? other approach?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to