Skip to content

Get extra logging (and consistency) when Proxying #6

merged 7 commits into from Jul 6, 2012
5 bettercache/
@@ -7,6 +7,7 @@
from httplib2 import Http
+import logging
from django.http import HttpResponse
from django.conf import settings
@@ -26,6 +27,7 @@ def is_hop_by_hop(header_name):
return header_name.lower() in _hop_headers
HOST = getattr(settings, 'BETTERCACHE_ORIGIN_HOST', 'localhost')
+logger = logging.getLogger(__name__)
if getattr(settings, 'BETTERCACHE_ORIGIN_PORT', None):
HOST += ":" + str(settings.BETTERCACHE_ORIGIN_PORT)
@@ -48,13 +50,14 @@ def proxy(request):
# TODO: try/except
http = Http()
http.follow_redirects = False
+ logger.debug("GET for: %s" % uri)
info, content = http.request(uri, 'GET', headers=headers)
response = HttpResponse(content, status=info.pop('status'))
for name, val in info.items():
if not is_hop_by_hop(name):
response[name] = val
+"PROXY to: %s" % uri)
return response
16 bettercache/
@@ -2,10 +2,10 @@
from bettercache.proxy import proxy
import logging
-logger = logging.getLogger()
+logger = logging.getLogger(__name__)
class BetterView(CachingMixin):
- """Accepts any path and attempts to server it from the cache. If it cannot
+ """Accepts any path and attempts to serve it from the cache. If it cannot
find the response in the cache, it will use ``bettercache.proxy`` to fulfill
it, and cache the response.
@@ -17,23 +17,21 @@ def get(self, request):
response, expired = self.get_cache(request)
# send off the celery task if it's expired
if expired:
-"sending task for %s" %request.build_absolute_uri())
+"EXPIRED sending task for %s" % request.build_absolute_uri())
self.send_task(request, response)
elif response:
-"not sending task for %s" %request.build_absolute_uri())
+ logger.debug("not sending task for %s" % request.build_absolute_uri())
-"cache miss for %s" %request.build_absolute_uri())
+"MISS for: %s" % request.build_absolute_uri())
# if response is still none we have to proxy
if response is None:
-'request %s proxied' %request.build_absolute_uri())
+ logger.debug('PROXY from: %s' % request.build_absolute_uri())
response = proxy(request)
- #TODO: delete the following two lines
- #self.set_cache(request, response)
response['X-Bettercache-Proxy'] = 'true'
response['X-Bettercache-Proxy'] = 'false'
-'request %s from cache' %request.build_absolute_uri())
+'HIT for: %s' % request.build_absolute_uri())
return response
Something went wrong with that request. Please try again.