source: src/django_gheat/wlheatmap/osm_proxy.py@ 9749

Last change on this file since 9749 was 9549, checked in by rick, 13 years ago
  • Caches are now fully-file based as memcached was not working well with large entries (like images).
  • OSM django proxy is way to slow, rewrite to use apache balanced proxy members.
  • Use HTTPD mod_cache to cache heavy image generation work.
File size: 711 bytes
Line 
1#
2# Hack to cache OSM tile images locally, using file based django caching
3#
4# Rick van der Zwet <info@rickvanderzwet.nl>
5#
6from django.views.decorators.cache import cache_page
7from django.http import HttpResponse
8
9import settings
10import random
11import urllib
12
13import logging
14logger = logging.getLogger(__name__)
15
16
17# Create your views here.
18@cache_page(60 * 60 * 24 * 7, cache="osm_proxy")
19def osm_proxy(request,zoom,x,y):
20 mirror = random.choice(['a','b','c'])
21 url = 'http://%s.tile.openstreetmap.org/%s/%s/%s.png' % (mirror, zoom, x, y)
22 logger.info("Fetching tile from %s" % url)
23 data = urllib.urlopen(url).read()
24 response = HttpResponse(mimetype="image/png")
25 response.write(data)
26 return response
Note: See TracBrowser for help on using the repository browser.