def _set_cache(self, app, config):
import_me = config['CACHE_TYPE']
if '.' not in import_me:
from . import backends
try:
cache_obj = getattr(backends, import_me)
except AttributeError:
raise ImportError("%s is not a valid FlaskCache backend" % (
import_me))
else:
cache_obj = import_string(import_me)
cache_args = config['CACHE_ARGS'][:]
cache_options = {'default_timeout': config['CACHE_DEFAULT_TIMEOUT']}
if config['CACHE_OPTIONS']:
cache_options.update(config['CACHE_OPTIONS'])
if not hasattr(app, 'extensions'):
app.extensions = {}
app.extensions.setdefault('cache', {})
app.extensions['cache'][self] = cache_obj(
app, config, cache_args, cache_options)
评论列表
文章目录