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/7195dea61d1d8ac0/a326cd9fee7fe2dd
- 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