Django's query result caching

51 views
Skip to first unread message

termopro

unread,
Dec 1, 2014, 11:45:00 AM12/1/14
to django...@googlegroups.com

I am creating a website using Django 1.7 and GeoDjango. I've hit the point when i need to optimize website speed.

One of the bottlenecks is query execution. There are some queries which run slowly even when optimized. So i'd like to cache query results and store them in Redis.

The problem that i am getting is that i cannot cache some query results. Particularly the ones containing geometry types and distance calculations. I hit "TypeError: can't pickle Binary objects" error.

What is the recommended/right way of caching Django/GeoDjango QuerySets ?

George Silva

unread,
Dec 1, 2014, 3:36:13 PM12/1/14
to django-users
You can convert your spatial results to WKT and store them in redis.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e3818a0-bf29-41c7-b21f-178806658417%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
George R. C. Silva
SIGMA Consultoria
----------------------------

termopro

unread,
Dec 1, 2014, 5:23:23 PM12/1/14
to django...@googlegroups.com
Could you please explain ?
Because I don't think it is possible to do it that way.

For example i have the following in my models.py:
class City(models.Model):
    name = models.CharField(max_length=40,db_index=True)
    state_name = models.CharField(max_length=30)
    location = models.PointField(null=True)
    objects = models.GeoManager()

And i do the following query:
City.objects.filter(location__distance_lt=(**some_location**, D(km=30))).distance(**some_location**).order_by('distance')[:15]

How do convert this query result to WKT ?
Reply all
Reply to author
Forward
0 new messages