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 <m...@nxtelevision.com> 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