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


Python cache.Cache方法代码示例

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


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

示例1: invalidate_board_cache

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def invalidate_board_cache(board_id: int):
    """Invalidates the cache for the given board in addition to the firehose."""
    cache_connection = cache.Cache()
    slip_bitmasks = 0, 1, 3, 7
    theme_list = app.config.get("THEME_LIST") or ("stock", "harajuku", "wildride")
    # invalidate full-page renders
    for bitmask in slip_bitmasks:
        for theme in theme_list:
            catalog_render_key = "board-%d-%d-%s-render" % (board_id, bitmask, theme)
            cache_connection.invalidate(catalog_render_key)
            firehose_render_key = "firehose-%d-%s-render" % (bitmask, theme)
            cache_connection.invalidate(firehose_render_key)
    # invalidate retrieved thread listings
    catalog_thread_key = "board-%d-threads" % board_id
    cache_connection.invalidate(catalog_thread_key)
    # invalidate firehose listing
    firehose_thread_key = "firehose-threads"
    cache_connection.invalidate(firehose_thread_key) 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:20,代码来源:thread.py

示例2: retrieve

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def retrieve(self, board_id):
        session = db.session
        cache_connection = cache.Cache()
        board_cache_key = "board-%d-threads" % board_id
        cached_threads = cache_connection.get(board_cache_key)
        if cached_threads:
            deserialized_threads = json.loads(cached_threads)
            for thread in deserialized_threads:
                thread["last_updated"] = datetime.datetime.utcfromtimestamp(thread["last_updated"])
            return deserialized_threads
        board = session.query(Board).filter(Board.id == board_id).one()
        thread_list = board.threads
        json_friendly = self._to_json(thread_list)
        cache_friendly = json.dumps(json_friendly, default=_datetime_handler)
        cache_connection.set(board_cache_key, cache_friendly)
        return json_friendly 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:18,代码来源:BoardListCatalog.py

示例3: _get_threads

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def _get_threads(self):
        firehose_cache_key = "firehose-threads"
        cache_connection = cache.Cache()
        cached_threads = cache_connection.get(firehose_cache_key)
        if cached_threads:
            deserialized_threads = json.loads(cached_threads)
            for thread in deserialized_threads:
                thread["last_updated"] = datetime.datetime.utcfromtimestamp(thread["last_updated"])
            return deserialized_threads
        firehose_limit = app.config["FIREHOSE_LENGTH"]
        raw_threads = db.session.query(Thread).order_by(desc(Thread.last_updated)).limit(firehose_limit).all()
        threads = BoardCatalog()._to_json(raw_threads)
        for thread in threads:
            db_thread = db.session.query(Thread).get(thread["id"])
            thread["board"] = db_thread.board
        cache_friendly = json.dumps(threads, default=_datetime_handler)
        cache_connection.set(firehose_cache_key, cache_friendly)
        return threads 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:20,代码来源:Firehose.py

示例4: __reduce__

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def __reduce__(self):
        arguments = (self.name, )
        state = self.__dict__.copy()
        if 'cache' in state:
            state.pop('cache')
            state['cache'] = Cache() # Empty the cache for storage
        return self.__class__, arguments, state, None, self.iteritems() 
开发者ID:Quantipy,项目名称:quantipy,代码行数:9,代码来源:stack.py

示例5: test_run_app

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def test_run_app(monkeypatch, caplog):
    """Test webapp init process."""

    monkeypatch.setattr(Cache, 'reload', lambda _: None)

    app.create_app()

    assert f'Starting (version {VMAAS_VERSION}).' in caplog.messages 
开发者ID:RedHatInsights,项目名称:vmaas,代码行数:10,代码来源:test_run_app.py

示例6: index

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def index():
    cache_connection = cache.Cache()
    current_theme = session.get("theme") or app.config.get("DEFAULT_THEME") or "stock"
    response_cache_key = "firehose-%d-%s-render" % (get_slip_bitmask(), current_theme)
    cached_response_body = cache_connection.get(response_cache_key)
    etag_value = "%s-%f"  % (response_cache_key, time.time())
    etag_cache_key = "%s-etag" % response_cache_key
    if cached_response_body:
        etag_header = request.headers.get("If-None-Match")
        current_etag = cache_connection.get(etag_cache_key)
        if etag_header:
            parsed_etag = parse_etags(etag_header)
            if parsed_etag.contains_weak(current_etag):
                return make_response("", 304)
        cached_response = make_response(cached_response_body)
        cached_response.set_etag(current_etag, weak=True)
        cached_response.headers["Cache-Control"] = "public,must-revalidate"
        return cached_response
    greeting = open("deploy-configs/index-greeting.html").read()
    threads = Firehose().get_impl()
    tag_styles = get_tags(threads)
    template = render_template("index.html", greeting=greeting, threads=threads, tag_styles=tag_styles)
    uncached_response = make_response(template)
    uncached_response.set_etag(etag_value, weak=True)
    uncached_response.headers["Cache-Control"] = "public,must-revalidate"
    cache_connection.set(response_cache_key, template)
    cache_connection.set(etag_cache_key, etag_value)
    return uncached_response 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:30,代码来源:main.py

示例7: catalog

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def catalog(board_id):
    current_theme = session.get("theme") or app.config.get("DEFAULT_THEME") or "stock"
    response_cache_key = "board-%d-%d-%s-render" % (board_id, get_slip_bitmask(), current_theme)
    cache_connection = cache.Cache()
    cached_response_body = cache_connection.get(response_cache_key)
    etag_value = "%s-%f" % (response_cache_key, time.time())
    etag_cache_key = "%s-etag" % response_cache_key
    if cached_response_body:
        etag_header = request.headers.get("If-None-Match")
        current_etag = cache_connection.get(etag_cache_key)
        if etag_header:
            parsed_etag = parse_etags(etag_header)
            if parsed_etag.contains_weak(current_etag):
                return make_response("", 304)
        cached_response = make_response(cached_response_body)
        cached_response.set_etag(current_etag, weak=True)
        cached_response.headers["Cache-Control"] = "public,must-revalidate"
        return cached_response
    threads = BoardCatalog().retrieve(board_id)
    board = db.session.query(Board).get(board_id)
    board_name = board.name
    render_for_catalog(threads)
    tag_styles = get_tags(threads)
    template = render_template("catalog.html", threads=threads, board=board, board_name=board_name, tag_styles=tag_styles)
    uncached_response = make_response(template)
    uncached_response.set_etag(etag_value, weak=True)
    uncached_response.headers["Cache-Control"] = "public,must-revalidate"
    cache_connection.set(response_cache_key, template)
    cache_connection.set(etag_cache_key, etag_value)
    return uncached_response 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:32,代码来源:boards.py

示例8: render_post_collection

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def render_post_collection(posts, context, extensions):
    cache_connection = cache.Cache()
    for post in posts:
        cache_key = post_render_cache_key(context, post["id"])
        cached_render = cache_connection.get(cache_key)
        if cached_render:
            post["body"] = cached_render
            continue
        rendered_markdown = clean(markdown(post["body"], extensions=extensions),
                             ALLOWED_TAGS, ALLOWED_ATTRIBUTES)
        cache_connection.set(cache_key, rendered_markdown)
        post["body"] = rendered_markdown 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:14,代码来源:Post.py

示例9: url_for_post

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def url_for_post(post_id):
    cache_key = post_url_cache_key(post_id)
    cache_connection = cache.Cache()
    cached_url = cache_connection.get(cache_key)
    if cached_url:
        return cached_url
    from model.Thread import Thread
    thread = Thread.query.filter(Thread.posts.any(id=post_id)).one()
    post_url = url_for("threads.view", thread_id=thread.id) + "#" + str(post_id)
    cache_connection.set(cache_key, post_url)
    return post_url 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:13,代码来源:PostReplyPattern.py

示例10: retrieve

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def retrieve(self, thread_id):
        session = db.session
        thread = session.query(Thread).filter(Thread.id == thread_id).one()
        cache_connection = cache.Cache()
        cache_key = thread_posts_cache_key(thread_id)
        cached_posts = cache_connection.get(cache_key)
        if cached_posts:
            deserialized_posts = json.loads(cached_posts)
            for post in deserialized_posts:
                post["datetime"] = datetime.datetime.utcfromtimestamp(post["datetime"])
            return deserialized_posts
        posts = self._json_friendly(thread.posts, thread)
        cache_connection.set(cache_key, json.dumps(posts, default=_datetime_handler))
        return posts 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:16,代码来源:ThreadPosts.py

示例11: _ensure_connection

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def _ensure_connection(self):
        if not self._cache_connection:
            self._cache_connection = cache.Cache() 
开发者ID:DangerOnTheRanger,项目名称:maniwani,代码行数:5,代码来源:jinja_cache.py

示例12: lambda_handler

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def lambda_handler(event, _):
    parameters = ParameterStore(region=REGION_DEFAULT, role=boto3)
    account_id = event.get(
        'detail').get(
            'requestParameters').get('accountId')
    organizations = Organizations(role=boto3, account_id=account_id)
    parsed_event = Event(
        event=event,
        parameter_store=parameters,
        organizations=organizations,
        account_id=account_id
    )
    cache = Cache()

    account_path = "ROOT" if parsed_event.moved_to_root else parsed_event.organizations.build_account_path(
        parsed_event.destination_ou_id,
        [],  # Initial empty array to hold OU Path,
        cache
    )

    if parsed_event.moved_to_root or parsed_event.moved_to_protected:
        return parsed_event.create_output_object("adf-bootstrap/" + account_path)

    parsed_event.set_destination_ou_name()

    return parsed_event.create_output_object("adf-bootstrap/" + account_path) 
开发者ID:awslabs,项目名称:aws-deployment-framework,代码行数:28,代码来源:determine_event.py

示例13: cls

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def cls():
    return Cache() 
开发者ID:awslabs,项目名称:aws-deployment-framework,代码行数:4,代码来源:test_cache.py

示例14: test_build_account_path

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def test_build_account_path(cls):
    cls.client = Mock()
    cache = Cache()
    cls.client.list_parents.return_value = stub_organizations.list_parents_root
    cls.client.describe_organizational_unit.return_value = stub_organizations.describe_organizational_unit

    assert cls.build_account_path('some_ou_id', [], cache) == 'some_ou_name' 
开发者ID:awslabs,项目名称:aws-deployment-framework,代码行数:9,代码来源:test_organizations.py

示例15: __init__

# 需要导入模块: import cache [as 别名]
# 或者: from cache import Cache [as 别名]
def __init__(self, parameter_store, stage_parameters, comparison_parameters):
        self.parameter_store = parameter_store
        self.stage_parameters = stage_parameters
        self.comparison_parameters = comparison_parameters
        self.sts = STS()
        self.cache = Cache() 
开发者ID:awslabs,项目名称:aws-deployment-framework,代码行数:8,代码来源:resolver.py


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