Commits

Vadim Statishin  committed b14f582

Set cache timeout - 1 day

  • Participants
  • Parent commits e8438b3

Comments (0)

Files changed (3)

File geoobjects/geo.py

 # -*- encoding: utf-8 -*-
 from django.db.models import Q
 from django.core.cache import cache
-from models import GeobazaObjects, GeobazaRanges, DELIM
+from models import GeobazaObjects, GeobazaRanges, CACHE_TIMEOUT
 
 
 __author__ = 'vadim'
     if not objs:
         query = GeobazaObjects.objects.all()
         objs = list(query.filter(*where_args)[:limit]) if limit > 0 else list(query.filter(*where_args))
-        cache.set(key_cache, objs)
+        cache.set(key_cache, objs, CACHE_TIMEOUT)
     return objs

File geoobjects/models.py

 
 DEFAULT_GEO_LOCATION = 5279
 
+CACHE_TIMEOUT = 86400
 
 class GeobazaRanges(models.Model):
     start = models.CharField(max_length=15)
             try:
                 ob = cls.objects.all().extra(where=['ip_int <= %d AND ip_int + length >=%d' % (int_ip, int_ip)],
                                              order_by=['length']).get()
-                cache.set(key_cache, ob)
+                cache.set(key_cache, ob, CACHE_TIMEOUT)
             except ObjectDoesNotExist:
                 ob = None
         return ob
                 ob = GeobazaObjects.objects.get(pk=self.obj_id)
             except ObjectDoesNotExist:
                 ob = GeobazaObjects.objects.get(pk=DEFAULT_GEO_LOCATION)
-            cache.set(key_cache, ob)
+            cache.set(key_cache, ob, CACHE_TIMEOUT)
         return ob
 
 
         ob = cache.get(key_cache)
         if ob is None:
             ob = GeobazaObjects.objects.get(pk=obj_id)
-            cache.set(key_cache, ob)
+            cache.set(key_cache, ob, CACHE_TIMEOUT)
         return ob
 
     @cached_property
 
 setup(
     name='geoobjects',
-    version='0.2.5.12',
+    version='0.2.5.13',
     packages=['geoobjects', 'geoobjects.management', 'geoobjects.management.commands'],
     scripts=['scripts/geoobjects_import_mysql.sh'],
     install_requires=['django'],