|
Last change
on this file since 9648 was 9549, checked in by rick, 14 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 | #
|
|---|
| 6 | from django.views.decorators.cache import cache_page
|
|---|
| 7 | from django.http import HttpResponse
|
|---|
| 8 |
|
|---|
| 9 | import settings
|
|---|
| 10 | import random
|
|---|
| 11 | import urllib
|
|---|
| 12 |
|
|---|
| 13 | import logging
|
|---|
| 14 | logger = logging.getLogger(__name__)
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | # Create your views here.
|
|---|
| 18 | @cache_page(60 * 60 * 24 * 7, cache="osm_proxy")
|
|---|
| 19 | def 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.