I am caching my configuration class, I am passing the class to cache.ram()
and it will be called to create a new instance, and the instance will be
cached.
/modules/config.py
class Config():
> def __init__(self, db):
> # inside config I use cache to read config from db and sometimes
> from ConfigParser
> self.objects =
> self.db(self.db.configtable).select(cache=(cache.ram, 300))
In other modules
/modules/datamodel/user.py
class User(BaseModel):
> def __init__(self):
> from gluon import current
> self.cache = current.cache
> from config import Config
> self.config = self.cache('config', *Config*, time_expire=300)
> #caching an instance of Config
in controller:
def index():
> from datamodel.user import User
> user = User()
> return user.get_user_list() # this function implements
> parse_template and also caches the html.