Skip to content

Commit 5458927

Browse files
committed
use original tiles dir/file name for cache
1 parent 19fcdb7 commit 5458927

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Diff for: proxy.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# see also: https://pymotw.com/2/BaseHTTPServer/
1010

1111
import BaseHTTPServer
12-
import hashlib
12+
# import hashlib
1313
import os
1414
import urllib2
1515

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

2222
class CacheHandler(BaseHTTPServer.BaseHTTPRequestHandler):
2323
def do_GET(self):
24-
m = hashlib.md5()
25-
m.update(self.path)
26-
cache_filename = ".tiles/" + m.hexdigest()
24+
25+
dirname = ".tiles/" + os.path.dirname(self.path)[1:]
26+
filename = os.path.basename(self.path)
27+
28+
while not os.path.exists(dirname):
29+
# might be a race here
30+
try:
31+
os.makedirs(dirname)
32+
except:
33+
None
34+
35+
# m = hashlib.md5()
36+
# m.update(self.path)
37+
# cache_filename = ".tiles/" + m.hexdigest()
38+
cache_filename = dirname + "/" + filename
39+
2740
if os.path.exists(cache_filename):
28-
print "Cache hit"
41+
# print "Cache hit"
2942
data = open(cache_filename).readlines()
3043
else:
3144
print "Cache miss"

0 commit comments

Comments
 (0)