def oncall(request, *args, **kwargs): use_cache = get_cache_context(vary, True, request)[1] response = None if use_cache: cache_key = request.path.encode('utf-8') md5calc = md5() # add function arguments and keywords for arg in args: print arg md5calc.update(arg.encode("utf-8")) for k,v in kwargs.iteritems(): md5calc.update(k+str(v)) # Most themes have some kind of login box, so # store a per-user cache if logged in users # aren't taken out of caching already if 'user' not in vary and request.user.is_somebody: md5calc.update(request.user.display_name.encode('utf-8')) cache_key += '__%s' % md5calc.hexdigest() response = request.app.cache.get(cache_key) if response is None: response = f(request, *args, **kwargs) # make sure it's one of our request objects so that we # have the `make_conditional` method on it. Response.force_type(response) if use_cache and response.status_code == 200: response.freeze() request.app.cache.set(cache_key, response, timeout) response.make_conditional(request) return response
def close(self): Response.close(self) if self._socket is not None: self._socket.close() self._socket = None if self._httplib_resp is not None: self._httplib_resp.close() self._httplib_resp = None
def __init__(self, url, body, status=200, headers=None): Response.__init__(self, body, status, headers) self.url = url