本文整理汇总了Python中flask_cache.Cache.init_app方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.init_app方法的具体用法?Python Cache.init_app怎么用?Python Cache.init_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_cache.Cache
的用法示例。
在下文中一共展示了Cache.init_app方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_21_redis_url_custom_db
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test_21_redis_url_custom_db(self):
config = {
'CACHE_TYPE': 'redis',
'CACHE_REDIS_URL': 'redis://localhost:6379/2',
}
cache = Cache()
cache.init_app(self.app, config=config)
rconn = self.app.extensions['cache'][cache] \
._client.connection_pool.get_connection('foo')
assert rconn.db == 2
示例2: test_20_redis_url_default_db
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test_20_redis_url_default_db(self):
config = {
'CACHE_TYPE': 'redis',
'CACHE_REDIS_URL': 'redis://localhost:6379',
}
cache = Cache()
cache.init_app(self.app, config=config)
from werkzeug.contrib.cache import RedisCache
assert isinstance(self.app.extensions['cache'][cache], RedisCache)
rconn = self.app.extensions['cache'][cache] \
._client.connection_pool.get_connection('foo')
assert rconn.db == 0
示例3: Flask
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
# permissions and limitations under the License.
import os
import sys
from flask import Flask, jsonify, request
from flask import current_app
#from flask.ext.cache import Cache
from flask_cache import Cache
sys.path.append(os.path.abspath("../supv"))
from rf import *
#REST service random forest prediction
app = Flask(__name__)
cache = Cache()
app.config['CACHE_TYPE'] = 'simple'
cache.init_app(app)
configPath = sys.argv[1]
portNum = int(sys.argv[2])
@app.route('/rf/predict/<string:recs>', methods=['GET'])
def predict(recs):
print recs
nrecs = recs.replace(",,", "\n")
print nrecs
resp = getResponse(nrecs)
return resp
@app.route('/rf/predict/batch', methods=['GET', 'POST'])
def batchPredict():
示例4: test_17_dict_config
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test_17_dict_config(self):
cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(self.app)
assert cache.config['CACHE_TYPE'] == 'simple'
示例5: test_19_dict_config_both
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test_19_dict_config_both(self):
cache = Cache(config={'CACHE_TYPE': 'null'})
cache.init_app(self.app, config={'CACHE_TYPE': 'simple'})
from werkzeug.contrib.cache import SimpleCache
assert isinstance(self.app.extensions['cache'][cache], SimpleCache)
示例6: register_cache
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def register_cache(app):
cache = Cache()
cache.init_app(app)
return cache
示例7: register_cache
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def register_cache(app):
cache = Cache(config={'CACHE_TYPE': 'redis'})
cache.init_app(app)
return cache
示例8: test
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test(data):
return data['message'].startswith('v2ex')
def handle(data, cache=None, **kwargs):
message = data['message']
ids = fetch(cache=cache, force=(True if u'刷新' in message else False))
contents = []
for id in ids:
topic = cache.get(TOPIC_KEY.format(id))
if not topic:
continue
node = topic['node']
msg = u'<{0}|{1} [{2}]> <{3}|{4}>'.format(TOPIC_URL.format(id),
cgi.escape(topic['title']),
topic['published'],
NODE_URL.format(node),
node)
contents.append(msg)
return '\n'.join(contents)
if __name__ == '__main__':
from flask import Flask
from flask_cache import Cache
app = Flask(__name__)
cache = Cache()
cache.init_app(app, config={'CACHE_TYPE': 'simple'})
with app.app_context():
print handle({'message': 'v2ex'}, cache, app)
示例9: test_21_init_app_sets_app_attribute
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
def test_21_init_app_sets_app_attribute(self):
cache = Cache()
cache.init_app(self.app)
assert cache.app == self.app
示例10: FlaskJanitoo
# 需要导入模块: from flask_cache import Cache [as 别名]
# 或者: from flask_cache.Cache import init_app [as 别名]
class FlaskJanitoo(object):
def __init__(self, app=None, options=None, db=None):
self._app = app
self._db = db
self.options = options
if self.options is not None and 'conf_file' in self.options and self.options['conf_file'] is not None:
logging_fileConfig(self.options['conf_file'])
self._listener = None
self._listener_lock = None
self._sleep = 0.25
self.menu_left = []
# Bower
self.bower = Bower()
# Caching
self.cache = Cache()
def __del__(self):
"""
"""
try:
self.stop_listener()
except Exception:
pass
def init_app(self, app, options, db=None):
"""
"""
if app is not None:
self._app = app
if options is not None:
self.options = options
if db is not None:
self._db = db
if self.options is not None and 'conf_file' in self.options and self.options['conf_file'] is not None:
logging_fileConfig(self.options['conf_file'])
# Flask-Cache
self.cache.init_app(self._app)
# Flask-Bower
self.bower.init_app(self._app)
self._event_manager = EventManager(self._app)
self._app.jinja_env.globals["emit_event"] = self._event_manager.template_emit
if not hasattr(self._app, 'extensions'):
self._app.extensions = {}
self._app.extensions['options'] = self.options
self._app.extensions['bower'] = self.bower
self._app.extensions['cache'] = self.cache
self._app.extensions['janitoo'] = self
try:
self._sleep = int(self._app.config['FLASKJANITOO_SLEEP'])
if self._sleep <= 0 :
self._sleep = 0.25
except KeyError:
self._sleep = 0.25
except ValueError:
self._sleep = 0.25
# Use the newstyle teardown_appcontext if it's available,
# otherwise fall back to the request context
if hasattr(self._app, 'teardown_appcontext'):
self._app.teardown_appcontext(self.teardown)
else:
self._app.teardown_request(self.teardown)
signal.signal(signal.SIGTERM, self.signal_term_handler)
signal.signal(signal.SIGINT, self.signal_term_handler)
self._listener_lock = threading.Lock()
self.create_listener()
def create_listener(self):
"""Create the listener on first call
"""
self._listener = ListenerThread(self._app, self.options)
@property
def listener(self):
"""Start the listener on first call
"""
self.start_listener()
return self._listener
def start_listener(self):
"""Start the listener on first call
"""
try:
self._listener_lock.acquire()
if not self._listener.is_alive():
self._listener.start()
finally:
self._listener_lock.release()
def stop_listener(self):
"""Stop the listener
"""
try:
self._listener_lock.acquire()
self._listener.stop()
try:
self._listener.join()
#.........这里部分代码省略.........