當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。