Ejemplo n.º 1
0
    def put(self, variant, size):
        """Store the current variant in the cache."""
        request = cherrypy.serving.request
        response = cherrypy.serving.response

        uri = cherrypy.url(qs=request.query_string)
        uricache = self.store.get(uri)
        if uricache is None:
            uricache = AntiStampedeCache()
            uricache.selecting_headers = [
                e.value for e in response.headers.elements('Vary')
            ]
            self.store[uri] = uricache

        if len(self.store) < self.maxobjects:
            total_size = self.cursize + size

            # checks if there's space for the object
            if (size < self.maxobj_size and total_size < self.maxsize):
                # add to the expirations list
                expiration_time = response.time + self.delay
                bucket = self.expirations.setdefault(expiration_time, [])
                bucket.append((size, uri, uricache.selecting_headers))

                # add to the cache
                header_values = [
                    request.headers.get(h, '')
                    for h in uricache.selecting_headers
                ]
                uricache[tuple(sorted(header_values))] = variant
                self.tot_puts += 1
                self.cursize = total_size
Ejemplo n.º 2
0
 def put(self, variant, size):
     """Store the current variant in the cache."""
     request = cherrypy.serving.request
     response = cherrypy.serving.response
     
     uri = cherrypy.url(qs=request.query_string)
     uricache = self.store.get(uri)
     if uricache is None:
         uricache = AntiStampedeCache()
         uricache.selecting_headers = [
             e.value for e in response.headers.elements('Vary')]
         self.store[uri] = uricache
     
     if len(self.store) < self.maxobjects:
         total_size = self.cursize + size
         
         # checks if there's space for the object
         if (size < self.maxobj_size and total_size < self.maxsize):
             # add to the expirations list
             expiration_time = response.time + self.delay
             bucket = self.expirations.setdefault(expiration_time, [])
             bucket.append((size, uri, uricache.selecting_headers))
             
             # add to the cache
             header_values = [request.headers.get(h, '')
                              for h in uricache.selecting_headers]
             uricache[tuple(sorted(header_values))] = variant
             self.tot_puts += 1
             self.cursize = total_size
Ejemplo n.º 3
0
def header_elements(fieldname, fieldvalue):
    if not fieldvalue:
        return []
    result = []
    for element in fieldvalue.split(','):
        if fieldname.startswith('Accept') or fieldname == 'TE':
            hv = AcceptElement.from_str(element)
        else:
            hv = HeaderElement.from_str(element)
        result.append(hv)

    return list(reversed(sorted(result)))
Ejemplo n.º 4
0
def header_elements(fieldname, fieldvalue):
    if not fieldvalue:
        return []
    result = []
    for element in fieldvalue.split(','):
        if fieldname.startswith('Accept') or fieldname == 'TE':
            hv = AcceptElement.from_str(element)
        else:
            hv = HeaderElement.from_str(element)
        result.append(hv)

    return list(reversed(sorted(result)))
Ejemplo n.º 5
0
 def get(self):
     request = cherrypy.serving.request
     self.tot_gets += 1
     uri = cherrypy.url(qs=request.query_string)
     uricache = self.store.get(uri)
     if uricache is None:
         return
     header_values = [ request.headers.get(h, '') for h in uricache.selecting_headers ]
     variant = uricache.wait(key=tuple(sorted(header_values)), timeout=self.antistampede_timeout, debug=self.debug)
     if variant is not None:
         self.tot_hist += 1
     return variant
Ejemplo n.º 6
0
def header_elements(fieldname, fieldvalue):
    """Return a sorted HeaderElement list from a comma-separated header string."""
    if not fieldvalue:
        return []

    result = []
    for element in fieldvalue.split(","):
        if fieldname.startswith("Accept") or fieldname == 'TE':
            hv = AcceptElement.from_str(element)
        else:
            hv = HeaderElement.from_str(element)
        result.append(hv)

    return list(reversed(sorted(result)))
Ejemplo n.º 7
0
def header_elements(fieldname, fieldvalue):
    """Return a sorted HeaderElement list from a comma-separated header string."""
    if not fieldvalue:
        return []

    result = []
    for element in fieldvalue.split(","):
        if fieldname.startswith("Accept") or fieldname == "TE":
            hv = AcceptElement.from_str(element)
        else:
            hv = HeaderElement.from_str(element)
        result.append(hv)

    return list(reversed(sorted(result)))
Ejemplo n.º 8
0
 def GET(self):
     return six.text_type(sorted(user_lookup.keys()))
Ejemplo n.º 9
0
 def multipart_form_data(self, **kwargs):
     return repr(list(sorted(kwargs.items())))
 def GET(self):
     return unicodestr(sorted(user_lookup.keys()))
 def GET(self):
     return six.text_type(sorted(user_lookup.keys()))
Ejemplo n.º 12
0
 def GET(self):
     return unicodestr(sorted(user_lookup.keys()))