Changeset 9392 for src/django_gheat


Ignore:
Timestamp:
Jul 12, 2011, 11:10:22 AM (13 years ago)
Author:
rick
Message:

Get rid of the poor-mans-cache implementation and uses the django buildin memory one by default.

Remove some old logging lines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/wlheatmap/tile.py

    r9188 r9392  
    44#
    55# Rick van der Zwet <info@rickvanderzwet.nl>
    6 from django.core.cache import cache
    76from django.core.management import setup_environ
    87from django.db.models import Max
    98from django.http import HttpResponse
     9from django.views.decorators.cache import cache_page
    1010from gheat.models import *
    11 import logging
    1211import pygame
    1312import sys
     
    2322except ImportError:
    2423  pass
    25 
    26 logging.basicConfig(level=logging.DEBUG)
    27 log = logging.getLogger('tile')
    2824
    2925class PyGamePicture():
     
    247243    #im.add_point((xcoord,ycoord),float(signal_normalized) / meters_per_pixel,colour, MAX_SIGNAL - meting.signaal)
    248244 
    249   log.info("BoundingBox NW: %s" % nw_deg)
    250   log.info("BoundingBox SE: %s" % se_deg)
    251   log.info("")
    252   log.info("MetingBox   NW: %.5f,%.5f" % (lat_max, lon_min))
    253   log.info("MetingBox   SE: %.5f,%.5f" % (lat_min, lon_max))
    254   log.info("")
    255   log.info("Metingen Count: %s" % metingen.count())
    256 
    257245  im.center_crop((SIZE,SIZE))
    258246  return im
     
    260248
    261249# Create your views here.
     250@cache_page(60 * 60 * 24)
    262251def 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 
    270   hash_key = TileCache.make_key("%s %s %s %s" % (zoom, x ,y, request.GET.urlencode()))
    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)
     252  raise KeyError("foo")
     253  filter = {}
     254  colour = (255,0,0)
     255  for key, value in request.GET.iteritems():
     256    if key == 'colour':
     257      colour = tuple(map(int,value.split(',')))
     258    else:
     259      filter[key] = value
     260  now = time.time()
     261  im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour)
     262  data = im.get_image('png')
    293263
    294264  response = HttpResponse(mimetype="image/png")
Note: See TracChangeset for help on using the changeset viewer.