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


Python cherrypy._cache方法代码示例

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


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

示例1: tee_output

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import _cache [as 别名]
def tee_output():
    """Tee response output to cache storage. Internal."""
    # Used by CachingTool by attaching to request.hooks

    request = cherrypy.serving.request
    if 'no-store' in request.headers.values('Cache-Control'):
        return

    def tee(body):
        """Tee response.body into a list."""
        if ('no-cache' in response.headers.values('Pragma') or
                'no-store' in response.headers.values('Cache-Control')):
            for chunk in body:
                yield chunk
            return

        output = []
        for chunk in body:
            output.append(chunk)
            yield chunk

        # Save the cache data, but only if the body isn't empty.
        # e.g. a 304 Not Modified on a static file response will
        # have an empty body.
        # If the body is empty, delete the cache because it
        # contains a stale Threading._Event object that will
        # stall all consecutive requests until the _Event times
        # out
        body = b''.join(output)
        if not body:
            cherrypy._cache.delete()
        else:
            cherrypy._cache.put((response.status, response.headers or {},
                                 body, response.time), len(body))

    response = cherrypy.serving.response
    response.body = tee(response.body) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:39,代码来源:caching.py

示例2: tee_output

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import _cache [as 别名]
def tee_output():
    """Tee response output to cache storage. Internal."""
    # Used by CachingTool by attaching to request.hooks

    request = cherrypy.serving.request
    if 'no-store' in request.headers.values('Cache-Control'):
        return

    def tee(body):
        """Tee response.body into a list."""
        if ('no-cache' in response.headers.values('Pragma') or
                'no-store' in response.headers.values('Cache-Control')):
            for chunk in body:
                yield chunk
            return

        output = []
        for chunk in body:
            output.append(chunk)
            yield chunk

        # save the cache data
        body = ntob('').join(output)
        cherrypy._cache.put((response.status, response.headers or {},
                             body, response.time), len(body))

    response = cherrypy.serving.response
    response.body = tee(response.body) 
开发者ID:naparuba,项目名称:opsbro,代码行数:30,代码来源:caching.py

示例3: tee_output

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import _cache [as 别名]
def tee_output():
    """Tee response output to cache storage. Internal."""
    # Used by CachingTool by attaching to request.hooks
    
    request = cherrypy.serving.request
    if 'no-store' in request.headers.values('Cache-Control'):
        return
    
    def tee(body):
        """Tee response.body into a list."""
        if ('no-cache' in response.headers.values('Pragma') or
            'no-store' in response.headers.values('Cache-Control')):
            for chunk in body:
                yield chunk
            return
        
        output = []
        for chunk in body:
            output.append(chunk)
            yield chunk
        
        # save the cache data
        body = ntob('').join(output)
        cherrypy._cache.put((response.status, response.headers or {},
                             body, response.time), len(body))
    
    response = cherrypy.serving.response
    response.body = tee(response.body) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:30,代码来源:caching.py


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