Python cherrypy._cache() Examples

The following are 5 code examples of cherrypy._cache(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cherrypy , or try the search function .
Example #1
Source File: caching.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #2
Source File: caching.py    From opsbro with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: caching.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #4
Source File: caching.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #5
Source File: caching.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
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)