Skip to content

Commit

Permalink
use original tiles dir/file name for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Nov 6, 2015
1 parent bfb043c commit 6326ceb
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# see also: https://pymotw.com/2/BaseHTTPServer/

import BaseHTTPServer
import hashlib
# import hashlib
import os
import urllib2

Expand All @@ -21,11 +21,24 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):

class CacheHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
m = hashlib.md5()
m.update(self.path)
cache_filename = ".tiles/" + m.hexdigest()

dirname = ".tiles/" + os.path.dirname(self.path)[1:]
filename = os.path.basename(self.path)

while not os.path.exists(dirname):
# might be a race here
try:
os.makedirs(dirname)
except:
None

# m = hashlib.md5()
# m.update(self.path)
# cache_filename = ".tiles/" + m.hexdigest()
cache_filename = dirname + "/" + filename

if os.path.exists(cache_filename):
print "Cache hit"
# print "Cache hit"
data = open(cache_filename).readlines()
else:
print "Cache miss"
Expand Down

0 comments on commit 6326ceb

Please sign in to comment.