You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
10 years ago
|
---
|
||
|
layout: post
|
||
|
status: publish
|
||
|
published: true
|
||
|
title: Django and Memcached
|
||
|
author:
|
||
|
display_name: sipp11
|
||
|
login: sipp11
|
||
|
email: sipp11@gmail.com
|
||
|
url: ''
|
||
|
author_login: sipp11
|
||
|
author_email: sipp11@gmail.com
|
||
|
wordpress_id: 889
|
||
|
wordpress_url: http://blog.10ninox.com/?p=889
|
||
|
date: '2014-01-23 02:20:24 +0700'
|
||
|
date_gmt: '2014-01-22 19:20:24 +0700'
|
||
|
categories:
|
||
|
- coding
|
||
|
tags:
|
||
|
- python
|
||
|
- django
|
||
|
- memcached
|
||
|
---
|
||
|
<p>Apparently it seems that both Django and Memcached work together flawlessly, but it fails silently most of the time which is hard to debug. One thing I've learned is never cache any queryset with Memcached since it wouldn't complain anything but doesn't do anything either. If you like to cache queryset, then using <code>LoMemCache</code>, <code>FileBasedCache</code>, <code>DummyCache</code> or whatever which is not Memcached. Everything will be all good.</p>
|
||
|
<p>Otherwise, you can separate cache into couple things then push queryset to one which is not Memcached.</p>
|
||
|
<pre>CACHES = {
|
||
|
'default': {
|
||
|
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
||
|
'LOCATION': '127.0.0.1:11211'
|
||
|
},
|
||
|
'queryset': {
|
||
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
|
||
|
},
|
||
|
}</pre>
|
||
|
<p>Then you can using <code>get_cache</code> to pick whatever you want</p>
|
||
|
<pre>
|
||
|
from django.core.cache import get_cache, cache
|
||
|
mycache = get_cache('queryset')
|
||
|
</pre>
|
||
|
<p>While cache will still point to 'default' or Memcached one.</p>
|