Changeset 9188
- Timestamp:
- May 12, 2011, 1:19:43 PM (14 years ago)
- Location:
- src/django_gheat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/settings.py
r9139 r9188 6 6 DEBUG = True 7 7 TEMPLATE_DEBUG = DEBUG 8 9 # Required for Etags Caching Implementation 10 USE_ETAGS = True 8 11 9 12 ADMINS = ( … … 23 26 } 24 27 } 28 29 CACHES = { 30 'default': { 31 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 32 'LOCATION': 'unique-snowflake' 33 } 34 } 35 25 36 26 37 # Local time zone for this installation. Choices can be found here: … … 97 108 98 109 MIDDLEWARE_CLASSES = ( 110 'django.middleware.cache.UpdateCacheMiddleware', 99 111 'django.middleware.common.CommonMiddleware', 112 'django.middleware.cache.FetchFromCacheMiddleware', 113 'django.middleware.http.ConditionalGetMiddleware', 100 114 'django.contrib.sessions.middleware.SessionMiddleware', 101 115 'django.contrib.auth.middleware.AuthenticationMiddleware', -
src/django_gheat/website/tile.py
r9184 r9188 4 4 # 5 5 # Rick van der Zwet <info@rickvanderzwet.nl> 6 from django.core.cache import cache 6 7 from django.core.management import setup_environ 7 8 from django.db.models import Max … … 260 261 # Create your views here. 261 262 def serve_tile(request,zoom,x,y): 263 """ 264 Showcase on caching and tile generation: 265 266 To make it 'easy' we use two types of caching here, memory cache expiring 267 at 30 seconds and database cache, always persistent storage on database. 268 """ 269 262 270 hash_key = TileCache.make_key("%s %s %s %s" % (zoom, x ,y, request.GET.urlencode())) 263 try: 264 d = TileCache.objects.get(key=hash_key) 265 data = d.data 266 except TileCache.DoesNotExist: 267 #log.setLevel(logging.DEBUG) 268 filter = {} 269 colour = (255,0,0) 270 for key, value in request.GET.iteritems(): 271 if key == 'colour': 272 colour = tuple(map(int,value.split(','))) 273 else: 274 filter[key] = value 275 now = time.time() 276 im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour) 277 log.info("Processing time: %s" % (time.time() - now)) 278 data = im.get_image('png') 279 r = TileCache.objects.create(key=hash_key,data=data) 271 data = cache.get(hash_key) 272 273 if not data: 274 try: 275 d = TileCache.objects.get(key=hash_key) 276 data = d.data 277 cache.set(hash_key,data, 30) 278 except TileCache.DoesNotExist: 279 #log.setLevel(logging.DEBUG) 280 filter = {} 281 colour = (255,0,0) 282 for key, value in request.GET.iteritems(): 283 if key == 'colour': 284 colour = tuple(map(int,value.split(','))) 285 else: 286 filter[key] = value 287 now = time.time() 288 im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour) 289 log.info("Processing time: %s" % (time.time() - now)) 290 data = im.get_image('png') 291 cache.set(hash_key,data, 30) 292 r = TileCache.objects.create(key=hash_key,data=data) 280 293 281 294 response = HttpResponse(mimetype="image/png")
Note:
See TracChangeset
for help on using the changeset viewer.