当前位置: 首页>>代码示例>>Python>>正文


Python Cache.init_app方法代码示例

本文整理汇总了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
开发者ID:mlenzen,项目名称:flask-cache,代码行数:12,代码来源:test_cache.py

示例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
开发者ID:mlenzen,项目名称:flask-cache,代码行数:14,代码来源:test_cache.py

示例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():
开发者ID:pranab,项目名称:avenir,代码行数:33,代码来源:rfsvc.py

示例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'
开发者ID:mlenzen,项目名称:flask-cache,代码行数:7,代码来源:test_cache.py

示例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)
开发者ID:mlenzen,项目名称:flask-cache,代码行数:7,代码来源:test_cache.py

示例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
开发者ID:HogwartsRico,项目名称:maple-bbs,代码行数:6,代码来源:extensions.py

示例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
开发者ID:Aoshee,项目名称:maple-blog,代码行数:6,代码来源:clear_cache.py

示例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)
开发者ID:imlyj,项目名称:slack_bot,代码行数:32,代码来源:v2ex.py

示例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
开发者ID:sh4nks,项目名称:flask-cache,代码行数:6,代码来源:test_cache.py

示例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()
#.........这里部分代码省略.........
开发者ID:bibi21000,项目名称:janitoo_flask,代码行数:103,代码来源:__init__.py


注:本文中的flask_cache.Cache.init_app方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。