Web2Py + GAE + Memcache | How to Implement in Web2Py

33 views
Skip to first unread message

PRACHI VAKHARIA

unread,
Feb 25, 2018, 5:19:42 AM2/25/18
to web...@googlegroups.com
  1. How to deploy Web2Py+Memcache on GAE
  2. How does one configure and also monitor the memcache server on GAE from web2py?
The description and details here are not enough or clear or explanative for a beginner.


For a model like this, how to implement Memchache on GAE for the table 'Articles'?

if request.env.web2py_runtime_gae
    htmlDB = DAL('google:datastore')
    AuthDB = DAL('google:datastore')
    session.connect(request, response, db=AuthDB) #???

    from gluon.contrib.gae_memcache import MemcacheClient
    from gluon.contrib.memdb import MEMDB
    cache.memcache = MemcacheClient(request)
    cache.ram = cache.disk = cache.memcache
    session.connect(request,response,db=MEMDB(cache.memcache.client)) #???

else:
    htmlDB = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
    AuthDB = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(AuthDB) #???
crud, service, plugins = Crud(htmlDB), Service(), PluginManager()
auth.define_tables(username=False, signature=False)

htmlDB.define_table('Articles',
    Field('Title'),
    Field('Abstract', 'text', label="Enter Abstract"),
    Field('Author'),
    Field('DatedOn', 'date', default=request.now, label="Date of Article"),
    format='%(Title)s')


 Objective: To cache the 'Articles' in Memcache in GAE.
 
Is the following the right way to do that in controller for the two functions? 
 
def List():
List = htmlDB().select(htmlDB.Articles.ALL, orderby=~htmlDB.Articles.DatedOn,  cache=(cache.memcache,86400),cacheable=True )
    return dict(List=List)

def Article():
    Article = htmlDB.Articles( request.args(0) ) or redirect(URL('Articles', 'List.html'),  cache=(cache.memcache,86400),cacheable=True )
    return dict(Article=Article)

List  is supposed to list all articles and cache them.
Article  is supposed to show one article from the list that has been cached. 

How does one achieve that using Web2Py + GAE + Memcache on GAE?

 
All help will be greatly appreciated! Thank you!


EOM 
Reply all
Reply to author
Forward
0 new messages