public
Last active

Using Django trunk with the python-memcache background, I can set the cache, but not get from it. But it's definitely setting, because you can see that the underlying memcache instance (cache._cache) is able to get -- it's just django's cache.get() method

  • Download Gist
Cache settings
1 2 3 4 5 6 7
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'KEY_PREFIX': 'barstar_',
}
}
F'd up memcaching with Django.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
>>> from django.core.cache import cache
>>> cache.clear()
>>> cache.get('testing_yo')
>>> cache.set('testing_yo', 'testing, yo!', 300)
>>> cache.key_prefix
'barstar_'
>>>
>>> # Using Django's cache framework's get method
>>> cache.get('testing_yo')
>>> cache.get('%stesting_yo' % cache.key_prefix)
>>>
>>> # Using the underlying memcached instance
>>> cache._cache.get('testing_yo')
'testing, yo!'
>>> cache._cache.get('%stesting_yo' % cache.key_prefix)
>>>
For good measure, without the KEY_PREFIX in the settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
>>> from django.core.cache import cache
>>> cache.clear()
>>> cache.get('testing_yo')
>>> cache.set('testing_yo', 'testing, yo!', 300)
>>> cache.key_prefix
''
>>>
>>> # Using Django's cache framework's get method - THIS IS THE REAL ISSUE
>>> cache.get('testing_yo')
>>>
>>> # Using the underlying memcached instance - THIS IS JUST HERE TO GIVE MORE INFO
>>> cache._cache.get('testing_yo')
'testing, yo!'
>>> cache._cache.get('%stesting_yo' % cache.key_prefix)
'testing, yo!'
>>> cache._cache.get('%s:1:testing_yo' % cache.key_prefix)
When I switch to the locmem backend, it works fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
>>> from django.core.cache import cache
>>> cache.clear()
>>> cache.get('testing_yo')
>>> cache.set('testing_yo', 'testing, yo!', 300)
>>> cache.key_prefix
''
>>>
>>> # Using Django's cache framework's get method - THIS IS THE REAL ISSUE
>>> cache.get('testing_yo')
'testing, yo!'
>>>
>>> # Using the underlying memcached instance - THIS IS JUST HERE TO GIVE MORE INFO
>>> cache._cache.get('testing_yo')
>>> cache._cache.get('%stesting_yo' % cache.key_prefix)
>>> cache._cache.get('%s:1:testing_yo' % cache.key_prefix)
"S'testing, yo!'\np1\n."
>>>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.