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


Python flask_caching.Cache方法代码示例

本文整理汇总了Python中flask_caching.Cache方法的典型用法代码示例。如果您正苦于以下问题:Python flask_caching.Cache方法的具体用法?Python flask_caching.Cache怎么用?Python flask_caching.Cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_caching的用法示例。


在下文中一共展示了flask_caching.Cache方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def test_cache():
    assert isinstance(cache, flask_caching.Cache)

# # Mailer
# def test_mailer_none():
#     assert mailer.mail is None
#
# def test_mailer_ses():
#     app = Flask(__name__)
#     app.config.update(**{
#         "MAILER_PROVIDER": "SES",
#         "MAILER_SES_ACCESS_KEY": "",
#         "MAILER_SES_SECRET_KEY": ""
#     })
#     mailer.init_app(app)
#     assert isinstance(mailer.mail, ses_mailer.Mail)
#
# def test_mailer_smtp():
#     app = Flask(__name__)
#     app.config.update(**{
#         "MAILER_PROVIDER": "SMTP",
#         "MAILER_SMTP_URI": "smtp://user:pass@mail.google.com:25",
#         "DEBUG": False,
#         "TESTING": False
#     })
#
#     mailer.init_app(app)
#     assert isinstance(mailer.mail, flask_mail.Mail) 
开发者ID:mardix,项目名称:assembly,代码行数:30,代码来源:_test_ext.py

示例2: _create_blogging_engine

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def _create_blogging_engine(self):
        cache = Cache(self.app, config={"CACHE_TYPE": "simple"})
        return BloggingEngine(self.app, self.storage, cache=cache) 
开发者ID:gouthambs,项目名称:Flask-Blogging,代码行数:5,代码来源:test_views.py

示例3: verify_password

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def verify_password(username_or_token, password=None):
    global database
    #database = lib.get_db()
    LOGGER = lib.get_logger(PROCESS)
    debug and LOGGER.warn("Will Verify User: {}, {}".format(username_or_token, password))
    # First try to verify via token
    user_rec = Users.verify_auth_token(app.config['SECRET_KEY'], username_or_token)
    if user_rec is None:
        # try to authenticate with username/password
        user_rec = Users.get(username_or_token, password)
    if user_rec is None:
        return False
    g.user = user_rec
    # Cache username<->user_id in redis for our stratum server
    redis_key = redis_userid_key + user_rec.username
    r.set(redis_key, user_rec.id)
    redis_key = redis_userid_key + user_rec.username.lower()
    r.set(redis_key, user_rec.id)
    return True

# XXX TODO:
# def change_password(username_or_token, new_password, password=None):
#     xxx TODO


#################
# -- Pool User Accounts 
开发者ID:grin-pool,项目名称:grin-pool,代码行数:29,代码来源:api.py

示例4: test_setup_cache_null_config

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def test_setup_cache_null_config(self):
        app = Flask(__name__)
        cache_config = {"CACHE_TYPE": "null"}
        assert isinstance(CacheManager._setup_cache(app, cache_config), Cache) 
开发者ID:apache,项目名称:incubator-superset,代码行数:6,代码来源:utils_tests.py

示例5: test_setup_cache_standard_config

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def test_setup_cache_standard_config(self):
        app = Flask(__name__)
        cache_config = {
            "CACHE_TYPE": "redis",
            "CACHE_DEFAULT_TIMEOUT": 60,
            "CACHE_KEY_PREFIX": "superset_results",
            "CACHE_REDIS_URL": "redis://localhost:6379/0",
        }
        assert isinstance(CacheManager._setup_cache(app, cache_config), Cache) is True 
开发者ID:apache,项目名称:incubator-superset,代码行数:11,代码来源:utils_tests.py

示例6: _setup_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def _setup_cache(app: Flask, cache_config: CacheConfig) -> Cache:
        """Setup the flask-cache on a flask app"""
        if isinstance(cache_config, dict):
            return Cache(app, config=cache_config)

        # Accepts a custom cache initialization function, returning an object compatible
        # with Flask-Caching API.
        return cache_config(app) 
开发者ID:apache,项目名称:incubator-superset,代码行数:10,代码来源:cache_manager.py

示例7: tables_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def tables_cache(self) -> Cache:
        return self._tables_cache 
开发者ID:apache,项目名称:incubator-superset,代码行数:4,代码来源:cache_manager.py

示例8: cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def cache(self) -> Cache:
        return self._cache 
开发者ID:apache,项目名称:incubator-superset,代码行数:4,代码来源:cache_manager.py

示例9: get

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def get(
        self,
        user: "User" = None,
        cache: "Cache" = None,
        thumb_size: Optional[WindowSize] = None,
    ) -> Optional[BytesIO]:
        """
            Get thumbnail screenshot has BytesIO from cache or fetch

        :param user: None to use current user or User Model to login and fetch
        :param cache: The cache to use
        :param thumb_size: Override thumbnail site
        """
        payload: Optional[bytes] = None
        thumb_size = thumb_size or self.thumb_size
        if cache:
            payload = cache.get(self.cache_key)
        if not payload:
            payload = self.compute_and_cache(
                user=user, thumb_size=thumb_size, cache=cache
            )
        else:
            logger.info("Loaded thumbnail from cache: %s", self.cache_key)
        if payload:
            return BytesIO(payload)
        return None 
开发者ID:apache,项目名称:incubator-superset,代码行数:28,代码来源:screenshots.py

示例10: get_from_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def get_from_cache(self, cache: "Cache") -> Optional[BytesIO]:
        payload = cache.get(self.cache_key)
        if payload:
            return BytesIO(payload)
        return None 
开发者ID:apache,项目名称:incubator-superset,代码行数:7,代码来源:screenshots.py

示例11: catalog_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def catalog_cache(response):
    response.headers['Cache-Control'] = 'max-age=300'
    return response 
开发者ID:TruSat,项目名称:trusat-backend,代码行数:5,代码来源:flask_server.py

示例12: init_app

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def init_app(self, app):
        """Initializes the Flask application with Common."""
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        if 'common' in app.extensions:
            raise RuntimeError("Flask-Common extension already initialized")

        app.extensions['common'] = self
        self.app = app

        if 'COMMON_FILESERVER_DISABLED' not in app.config:
            with app.test_request_context():

                # Configure WhiteNoise.
                app.wsgi_app = WhiteNoise(app.wsgi_app, root=url_for('static', filename='')[1:])

        self.cache = Cache(app, config={'CACHE_TYPE': app.config.get("COMMON_CACHE_TYPE", 'simple')})

        @app.before_request
        def before_request_callback():
            request.start_time = maya.now()

        @app.after_request
        def after_request_callback(response):
            if 'COMMON_POWERED_BY_DISABLED' not in current_app.config:
                response.headers['X-Powered-By'] = 'Flask'
            if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app.config:
                response.headers['X-Processed-Time'] = maya.now().epoch - request.start_time.epoch
            return response

        @app.route('/favicon.ico')
        def favicon():
            return redirect(url_for('static', filename='favicon.ico'), code=301) 
开发者ID:schedutron,项目名称:flask-common,代码行数:36,代码来源:flask_common.py

示例13: post

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def post(self):
        global database
        LOGGER = lib.get_logger(PROCESS)
        username = None
        password = None
        try:
            debug and print("json request = {}".format(request.form))
            username = request.form.get('username')
            password = request.form.get('password')
            debug and LOGGER.warn("PoolAPI_users POST: user:{} password:{}".format(username, password))
        except AttributeError as e:
            LOGGER.warn("Missing username or password - {}".format(str(e)))
        if username is None or password is None:
            response = jsonify({ 'message': 'Missing arguments: username and pasword required' })
            response.status_code = 400
            return response
        if username == "" or password == "":
            response = jsonify({ 'message': 'Missing arguments: username and pasword required' })
            response.status_code = 400
            return response
        if "." in username:
            response = jsonify({ 'message': 'Invalid Username: May not contain "."' })
            response.status_code = 400
            return response
        # Check if the username is taken
        exists = Users.check_username_exists(username)
        if exists:
            debug and print("Failed to add - conflict with existing user = {}".format(username))
            response = jsonify({ 'message': 'Conflict with existing account' })
            response.status_code = 409
            return response
        # Create the users record
        user_rec = Users.create(username, password)
        if user_rec is None:
            debug and print("Failed to add - unable to create a new user record")
            response = jsonify({ 'message': 'System Error: Failed to create account' })
            response.status_code = 500
            return response
        # initialize a worker_stats record for this user (previous block) so they get instance feedback on the UI
        lb = Blocks.get_latest()
        if lb is not None:
            height = Blocks.get_latest().height
            initial_stat = Worker_stats(datetime.utcnow(), height, user_rec.id)
            database.db.createDataObj(initial_stat)
        # Cache username<->user_id in redis for our stratum server
        redis_key = redis_userid_key + user_rec.username
        r.set(redis_key, user_rec.id)
        debug and print("Added user = {}".format(user_rec))
        response = jsonify({ 'username': user_rec.username, 'id': user_rec.id })
        response.status_code = 201
        return response

    #decorators = [limiter.limit("5/minute"), auth.login_required] 
开发者ID:grin-pool,项目名称:grin-pool,代码行数:55,代码来源:api.py

示例14: compute_and_cache

# 需要导入模块: import flask_caching [as 别名]
# 或者: from flask_caching import Cache [as 别名]
def compute_and_cache(  # pylint: disable=too-many-arguments
        self,
        user: "User" = None,
        thumb_size: Optional[WindowSize] = None,
        cache: "Cache" = None,
        force: bool = True,
    ) -> Optional[bytes]:
        """
        Fetches the screenshot, computes the thumbnail and caches the result

        :param user: If no user is given will use the current context
        :param cache: The cache to keep the thumbnail payload
        :param window_size: The window size from which will process the thumb
        :param thumb_size: The final thumbnail size
        :param force: Will force the computation even if it's already cached
        :return: Image payload
        """
        cache_key = self.cache_key
        if not force and cache and cache.get(cache_key):
            logger.info("Thumb already cached, skipping...")
            return None
        thumb_size = thumb_size or self.thumb_size
        logger.info("Processing url for thumbnail: %s", cache_key)

        payload = None

        # Assuming all sorts of things can go wrong with Selenium
        try:
            payload = self.get_screenshot(user=user)
        except Exception as ex:  # pylint: disable=broad-except
            logger.error("Failed at generating thumbnail %s", ex)

        if payload and self.window_size != thumb_size:
            try:
                payload = self.resize_image(payload, thumb_size=thumb_size)
            except Exception as ex:  # pylint: disable=broad-except
                logger.error("Failed at resizing thumbnail %s", ex)
                payload = None

        if payload and cache:
            logger.info("Caching thumbnail: %s %s", cache_key, str(cache))
            cache.set(cache_key, payload)
        return payload 
开发者ID:apache,项目名称:incubator-superset,代码行数:45,代码来源:screenshots.py


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