I'd like to use cache/memcache within my module files.

Example:

in db.py when request.env.web2py_runtime_gae I set this:
cache.ram = cache.disk = cache.memcache

In my module (lineitem.py):

#1
class Lineitem():
    def __init__(self, db, T=None):
        self.db = db
        self.T = T

    @cache(#2, time_expire=60*60*24*30, cache_model=cache.ram)
    def get_name(self, ref):
        q=self.db.lineitem.ref==ref
        lineitems = self.db(q).select(self.db.lineitem.ALL,
                                      limitby=(0,1),
                                      orderby=~self.db.lineitem.mDate)
        return lineitems[0].name

    @ #3
    def update_lineitem(ref, new_name, new_toll, new_date):
        write to db and update lineitem

Questions:
1. what do I need to add at #1 to access caching in a module?
2. I'd like to cache the name of every line item. what do I add as #2
so that each value of "ref" gets its own cache key?
3. can I, at point #3, clear the cache of all keys that refer to
"ref" ?

Reply via email to