Exemple #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
Exemple #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
Exemple #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)))
Exemple #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)))
Exemple #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
Exemple #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)))
Exemple #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)))
 def GET(self):
     return six.text_type(sorted(user_lookup.keys()))
Exemple #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()))
 def GET(self):
     return unicodestr(sorted(user_lookup.keys()))