• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python origin.origin_cache函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中warehouse.cache.origin.origin_cache函数的典型用法代码示例。如果您正苦于以下问题:Python origin_cache函数的具体用法?Python origin_cache怎么用?Python origin_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_response_hook

    def test_response_hook(self, seconds, keys):
        class Fake:
            pass

        class Cache:

            @staticmethod
            @pretend.call_recorder
            def cache(keys, request, response, seconds, stale_while_revalidate,
                      stale_if_error):
                pass

        response = pretend.stub()

        deco = origin.origin_cache(seconds, keys=keys)

        @deco
        def view(context, request):
            return response

        key_maker = pretend.call_recorder(
            lambda obj: origin.CacheKeys(cache=["one", "two"], purge=[])
        )
        cacher = Cache()
        context = Fake()
        callbacks = []
        request = pretend.stub(
            registry={"cache_keys": {Fake: key_maker}},
            find_service=lambda iface: cacher,
            add_response_callback=callbacks.append,
        )

        assert view(context, request) is response
        assert key_maker.calls == [pretend.call(context)]
        assert len(callbacks) == 1

        callbacks[0](request, response)

        assert cacher.cache.calls == [
            pretend.call(
                sorted(["one", "two"] + ([] if keys is None else keys)),
                request,
                response,
                seconds=seconds,
                stale_while_revalidate=None,
                stale_if_error=None,
            ),
        ]
开发者ID:miohtama,项目名称:warehouse,代码行数:48,代码来源:test_init.py


示例2: test_response_hook

    def test_response_hook(self, seconds):
        class Fake:
            pass

        class Cache:

            @staticmethod
            @pretend.call_recorder
            def cache(keys, request, response, seconds):
                pass

        response = pretend.stub()

        if seconds is None:
            deco = origin.origin_cache
        else:
            deco = origin.origin_cache(seconds)

        @deco
        def view(context, request):
            return response

        key_maker = pretend.call_recorder(lambda obj: ["one", "two"])
        cacher = Cache()
        context = Fake()
        callbacks = []
        request = pretend.stub(
            registry={"cache_keys": {Fake: key_maker}},
            find_service=lambda iface: cacher,
            add_response_callback=callbacks.append,
        )

        assert view(context, request) is response
        assert key_maker.calls == [pretend.call(context)]
        assert len(callbacks) == 1

        callbacks[0](request, response)

        assert cacher.cache.calls == [
            pretend.call(["one", "two"], request, response, seconds=seconds),
        ]
开发者ID:IanLee1521,项目名称:warehouse,代码行数:41,代码来源:test_init.py


示例3: cache_control

from sqlalchemy.orm.exc import NoResultFound

from warehouse.cache.http import cache_control
from warehouse.cache.origin import origin_cache
from warehouse.packaging.interfaces import IDownloadStatService
from warehouse.packaging.models import File, Release


@view_config(
    route_name="legacy.api.json.project",
    renderer="json",
    decorator=[
        cache_control(15 * 60),               # 15 minutes
        origin_cache(
            1 * 24 * 60 * 60,                 # 1 day
            stale_while_revalidate=5 * 60,    # 5 minutes
            stale_if_error=1 * 24 * 60 * 60,  # 1 day
        ),
    ],
)
def json_project(project, request):
    if project.name != request.matchdict.get("name", project.name):
        return HTTPMovedPermanently(
            request.current_route_path(name=project.name),
        )

    try:
        release = (
            request.db.query(Release)
                      .filter(Release.project == project)
                      .order_by(Release._pypi_ordering.desc())
开发者ID:JosephBywater,项目名称:warehouse,代码行数:31,代码来源:json.py


示例4: cache_control

from warehouse.cache.http import cache_control
from warehouse.cache.origin import origin_cache
from warehouse.packaging.interfaces import IDownloadStatService
from warehouse.packaging.models import File, Release, JournalEntry


@view_config(
    route_name="legacy.api.json.project",
    renderer="json",
    decorator=[
        cache_control(
            1 * 24 * 60 * 60,                         # 1 day
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=1 * 24 * 60 * 60,          # 1 day
        ),
        origin_cache(7 * 24 * 60 * 60),   # 7 days
    ],
)
def json_project(project, request):
    if project.name != request.matchdict.get("name", project.name):
        return HTTPMovedPermanently(
            request.current_route_path(name=project.name),
        )

    try:
        release = project.releases.order_by(
            Release._pypi_ordering.desc()
        ).limit(1).one()
    except NoResultFound:
        return HTTPNotFound()
开发者ID:maxking,项目名称:warehouse,代码行数:30,代码来源:json.py


示例5: Response

    return Response(status=403)


@view_config(context=DatabaseNotAvailable)
def service_unavailable(exc, request):
    return httpexception_view(HTTPServiceUnavailable(), request)


@view_config(
    route_name="robots.txt",
    renderer="robots.txt",
    decorator=[
        cache_control(1 * 24 * 60 * 60),  # 1 day
        origin_cache(
            1 * 24 * 60 * 60,  # 1 day
            stale_while_revalidate=6 * 60 * 60,  # 6 hours
            stale_if_error=1 * 24 * 60 * 60,  # 1 day
        ),
    ],
)
def robotstxt(request):
    request.response.content_type = "text/plain"
    return {}


@view_config(
    route_name="opensearch.xml",
    renderer="opensearch.xml",
    decorator=[
        cache_control(1 * 24 * 60 * 60),  # 1 day
        origin_cache(
开发者ID:craig5,项目名称:warehouse,代码行数:31,代码来源:views.py


示例6: origin_cache

from pyramid.view import view_config
from sqlalchemy.orm import joinedload

from warehouse.cache.origin import origin_cache
from warehouse.packaging.models import Project, Release
from warehouse.xml import XML_CSP


@view_config(
    route_name="rss.updates",
    renderer="rss/updates.xml",
    decorator=[
        origin_cache(
            1 * 24 * 60 * 60,  # 1 day
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=5 * 24 * 60 * 60,  # 5 days
            keys=["all-projects"],
        )
    ],
)
def rss_updates(request):
    request.response.content_type = "text/xml"

    request.find_service(name="csp").merge(XML_CSP)

    latest_releases = (
        request.db.query(Release)
        .options(joinedload(Release.project))
        .order_by(Release.created.desc())
        .limit(40)
        .all()
开发者ID:craig5,项目名称:warehouse,代码行数:31,代码来源:views.py


示例7: origin_cache

from pyramid.httpexceptions import HTTPMovedPermanently, HTTPNotFound
from pyramid.view import view_config
from sqlalchemy.orm.exc import NoResultFound

from warehouse.accounts.models import User
from warehouse.cache.origin import origin_cache
from warehouse.packaging.models import Release, Role


@view_config(
    route_name="packaging.project",
    renderer="packaging/detail.html",
    decorator=[
        origin_cache(
            1 * 24 * 60 * 60,                         # 1 day
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=5 * 24 * 60 * 60,          # 5 days
        ),
    ],
)
def project_detail(project, request):
    if project.name != request.matchdict.get("name", project.name):
        return HTTPMovedPermanently(
            request.current_route_path(name=project.name),
        )

    try:
        release = (
            request.db.query(Release)
                      .filter(Release.project == project)
                      .order_by(
开发者ID:ewdurbin,项目名称:warehouse,代码行数:31,代码来源:views.py


示例8: origin_cache

from sqlalchemy.orm.exc import NoResultFound

from warehouse.accounts.models import User
from warehouse.cache.http import cache_control
from warehouse.cache.origin import origin_cache
from warehouse.packaging.interfaces import IDownloadStatService, IFileStorage
from warehouse.packaging.models import Release, File, Role


@view_config(
    route_name="packaging.project",
    renderer="packaging/detail.html",
    decorator=[
        origin_cache(
            1 * 24 * 60 * 60,                         # 1 day
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=5 * 24 * 60 * 60,          # 5 days
        ),
    ],
)
def project_detail(project, request):
    if project.name != request.matchdict.get("name", project.name):
        return HTTPMovedPermanently(
            request.current_route_path(name=project.name),
        )

    try:
        release = (
            request.db.query(Release)
                      .options(joinedload(Release.uploader))
                      .filter(Release.project == project)
开发者ID:TakesxiSximada,项目名称:warehouse,代码行数:31,代码来源:views.py


示例9: cache_control

from warehouse.cache.http import cache_control
from warehouse.csrf import csrf_protect
from warehouse.sessions import uses_session
from warehouse.utils.http import is_safe_url


@view_config(
    route_name="accounts.profile",
    renderer="accounts/profile.html",
    decorator=[
        cache_control(
            1 * 24 * 60 * 60,                         # 1 day
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=1 * 24 * 60 * 60,          # 1 day
        ),
        origin_cache(30 * 24 * 60 * 60),  # 30 days
    ],
)
def profile(user, request):
    if user.username != request.matchdict.get("username", user.username):
        return HTTPMovedPermanently(
            request.current_route_path(username=user.username),
        )

    return {"user": user}


@forbidden_view_config()
@view_config(
    route_name="accounts.login",
    renderer="accounts/login.html",
开发者ID:maxking,项目名称:warehouse,代码行数:31,代码来源:views.py


示例10: cache_control

from warehouse.cache.http import cache_control
from warehouse.cache.origin import origin_cache
from warehouse.packaging.models import JournalEntry, File, Project, Release


@view_config(
    route_name="legacy.api.simple.index",
    renderer="legacy/api/simple/index.html",
    decorator=[
        cache_control(
            10 * 60,                                  # 10 minutes
            stale_while_revalidate=1 * 24 * 60 * 60,  # 1 day
            stale_if_error=1 * 24 * 60 * 60,          # 1 day
        ),
        origin_cache(7 * 24 * 60 * 60),   # 7 days
    ],
)
def simple_index(request):
    # Get the latest serial number
    serial = request.db.query(func.max(JournalEntry.id)).scalar() or 0
    request.response.headers["X-PyPI-Last-Serial"] = serial

    # Fetch the name and normalized name for all of our projects
    projects = (
        request.db.query(Project.name, Project.normalized_name)
                  .order_by(Project.normalized_name)
                  .all()
    )

    return {"projects": projects}
开发者ID:IanLee1521,项目名称:warehouse,代码行数:30,代码来源:simple.py


示例11: origin_cache

from pyramid.view import view_config
from sqlalchemy.orm.exc import NoResultFound

from warehouse.utils import readme
from warehouse.accounts.models import User
from warehouse.cache.origin import origin_cache
from warehouse.packaging.models import Project, Release, Role


@view_config(
    route_name="packaging.project",
    context=Project,
    renderer="packaging/detail.html",
    decorator=[
        origin_cache(
            1 * 24 * 60 * 60, stale_if_error=5 * 24 * 60 * 60  # 1 day, 5 days stale
        )
    ],
)
def project_detail(project, request):
    if project.name != request.matchdict.get("name", project.name):
        return HTTPMovedPermanently(request.current_route_path(name=project.name))

    try:
        release = (
            request.db.query(Release)
            .filter(Release.project == project)
            .order_by(Release.is_prerelease.nullslast(), Release._pypi_ordering.desc())
            .limit(1)
            .one()
        )
开发者ID:dstufft,项目名称:warehouse,代码行数:31,代码来源:views.py


示例12: cache_control


SITEMAP_MAXSIZE = 50000


Bucket = collections.namedtuple("Bucket", ["name", "modified"])


@view_config(
    route_name="index.sitemap.xml",
    renderer="sitemap/index.xml",
    decorator=[
        cache_control(1 * 60 * 60),  # 1 hour
        origin_cache(
            1 * 24 * 60 * 60,  # 1 day
            stale_while_revalidate=6 * 60 * 60,  # 6 hours
            stale_if_error=1 * 24 * 60 * 60,  # 1 day
            keys=["all-projects"],
        ),
    ],
)
def sitemap_index(request):
    request.response.content_type = "text/xml"

    request.find_service(name="csp").merge(XML_CSP)

    # We have > 50,000 URLs on PyPI and a single sitemap file can only support
    # a maximum of 50,000 URLs. We need to split our URLs up into multiple
    # files so we need to stick all of our URLs into buckets, in addition we
    # want our buckets to remain stable so that an URL won't change what bucket
    # it is in just because another URL is added or removed. Finally we also
    # want to minimize the number of buckets we have to reduce the number of
开发者ID:dstufft,项目名称:warehouse,代码行数:30,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python packages.insert函数代码示例发布时间:2022-05-26
下一篇:
Python application.Warehouse类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap