wow, thanks for that investigation...

it works well for the delete statement (which is what i needed)
just for information, the "get" statement returns : "A server error
occured. Please contact the administrator.".



Thank you Massimo for helping me,

regards,

--
Jérémie


On 13 août, 12:11, mdipierro <[email protected]> wrote:
> Now I see the problem. There is a little incompatibility between the
> way get(), set(),and delete() works in web2py between GAE and non-GAE.
>
> On GAE (gluon/contrib/gae_memcache.py
>
>     cache.memcache('time',lambda:time.ctime(),20)
>     cache.memcache.get(request.application+'/time')
>
> (uses the native get API key therefore the internal key is different)
> Same for get and delete
>
> On Non-GAE (gluon/contrib/memcache/__init__.py
>
>     cache.memcache('time',lambda:time.ctime(),20)
>     cache.memcache.get('time')
>
> (here get,set,delete have been redefined to consistently use the same
> key)
>
> This is not a major issue because get, set, delete are not documented
> as web2py APIs.
> Yet I think GAE implementation is right and it is wrong for the Non-
> GAE version to redefine memcache get/set/delete even if they make its
> use more intuitive.
>
> Perhaps this
>
> On Aug 13, 4:44 am, Jérémie <[email protected]> wrote:
>
> > Dear Massimo,
>
> > Thanks for having a look at my issue.
> > Unfortunately, even with the modification, i can't manage to have the
> > get and delete methods working...
>
> > i don't know if this is important but i am working locally on the GAE
> > dev-app server. i don't know if memcache is working on the same way.
>
> > Jérémie
>
> > On 13 août, 11:18, mdipierro <[email protected]> wrote:
>
> > > Dear Jeremie,
>
> > > I did not write the memcache code myself but I looked into it (gluon/
> > > contrib/memcache/__init__.py). I found this line
>
> > >         #key =
> > > self.__keyFormat__(key)
>
> > > And I am puzzled by why it is commented. I think it should not be. Can
> > > you try uncomment it and see if it works as you expect it.
>
> > > Massimo
>
> > > On Aug 13, 1:46 am, Jérémie <[email protected]> wrote:
>
> > > > Hello again,
>
> > > > Thank you for your answers.
>
> > > > I had and i still have really spent some time parsing the book and the
> > > > web2py google groups.
> > > > Thus, i tried something simplier but which doesn't work either as i
> > > > would have expected.
>
> > > > def makeMe():
> > > >     import time
> > > >     t = cache.memcache('time',lambda:time.ctime(),20)
> > > >     return t
>
> > > > def getMe():
> > > >     return cache.memcache.get('time')
>
> > > > --> returns None and i don't understand why
> > > > --> i expected it to return the cached value
>
> > > > def clearMe():
> > > >     return cache.memcache.delete('time')
>
> > > > --> return 1 (should be ok regarding of the doc)
> > > > --> yet, calling makmeMe() again still returns the cached variable
> > > > (although i thought the cached variable was deleted...)
>
> > > > Furthermore, a function with return cache.memcache.flush_all() do
> > > > works and clear the cache.
>
> > > > i have tried to understand how all that works thanks to :
> > > > - the book (http://www.web2py.com/book/default/chapter/11#Memcache)
> > > > - some topics of the google group, especially this one 
> > > > :http://groups.google.com/group/web2py/browse_thread/thread/7195dea61d...
> > > > - the contrib/memcache/memcache.py and cache.py
>
> > > > could you please explain me where i am wrong ?
>
> > > > thanks for your help,
> > > > regards,
>
> > > > --
> > > > Jérémie
>
> > > > On 11 août, 15:15, mdipierro <[email protected]> wrote:
>
> > > > > It will work if you setup gae memcache and point cache.ram to it. It
> > > > > is explained in the book in the GAE section
>
> > > > > On Aug 11, 7:45 am, howesc <[email protected]> wrote:
>
> > > > > > i thought that the query caching like:
> > > > > >   db(query).select(cache=...)
> > > > > > was not supported in web2py on GAE?  did i miss a detail somewhere?
>
> > > > > > since i thought it was not supported i have not yet tried to use it 
> > > > > > or
> > > > > > clear it.  sorry.
>
> > > > > > cfh
>
> > > > > > On Aug 8, 11:51 pm, Jérémie <[email protected]> wrote:
>
> > > > > > > Hello everyone,
>
> > > > > > > First of all, thank you Massimo and all the contributors for this
> > > > > > > great framework and all the documentation and support.
> > > > > > > I am kind of new on web2py and i am trying to use cache on Google 
> > > > > > > App
> > > > > > > Engine.
>
> > > > > > > Thanks to Robin's contribution (gae_memcache.py), i can use 
> > > > > > > cache.ram
> > > > > > > on GAE but keep on using the same syntax cache.ram).
> > > > > > > Yet, i tried to cache some database request and to clear cache 
> > > > > > > when
> > > > > > > the user updated the database with new or edited record.
>
> > > > > > > Here is the code i used (as i am quite also new to Python, let me 
> > > > > > > know
> > > > > > > if some part of my code is not "Pythonic" or "Web2py-ic").
>
> > > > > > > Caching the request (i call the same function for 3 databases):
>
> > > > > > > def getdata(database, bHidden = False):
> > > > > > >     """ General query for getting records in a database """
> > > > > > >     #check if hidden records are wanted
> > > > > > >     if bHidden:
> > > > > > >         query = (db[database].id>0)&(db[database].hidden==False)
> > > > > > >     else:
> > > > > > >         query = (db[database].id>0)
> > > > > > >     #query data and returns a dict
> > > > > > >     records = db(query).select(orderby=db[database].position,
> > > > > > > cache=(cache.ram,3600))
> > > > > > >     return dict([(row.id, row) for row in records])
>
> > > > > > > When user adds a new record (for example), i want to clear the 
> > > > > > > cache :
>
> > > > > > > def new_record():
> > > > > > >     """ Ajax call for creating a record and returning the new id 
> > > > > > > """
> > > > > > >     #Get the parameters posted by the script
> > > > > > >     database = request.vars.db
> > > > > > >     #Update database
> > > > > > >     id = db[database].insert()
> > > > > > >     #Clear cache
> > > > > > >     cache.ram.clear(db._uri + '.*FROM ' + database + ' WHERE.*')
> > > > > > >     return int(id)
>
> > > > > > > This works well with sqlite database but doesn't work with GAE.
> > > > > > > (of course, because, there is no "clear" method in 
> > > > > > > gae_memcache.py)
> > > > > > > Actually, there is no 'storage' attribute when using memcache on 
> > > > > > > GAE.
>
> > > > > > > Here are my questions :
> > > > > > > 1. Is there any method or attribute similar to 'storage' for 
> > > > > > > memcache
> > > > > > > on GAE ? And could it be implemented in gae_memcache.py ?
> > > > > > > 2. Am i doing this all wrong ? Should i better cache each dict
> > > > > > > individually with memcache ?
> > > > > > > 3. Should i handle this in a completely different way ?
>
> > > > > > > Let me know i am not clear enough,
> > > > > > > Thanks for your help,
>
> > > > > > > Regards,
>
> > > > > > > --
> > > > > > > Jérémie

Reply via email to