Skip to content

Instantly share code, notes, and snippets.

@jcroft
Created January 23, 2011 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcroft/792466 to your computer and use it in GitHub Desktop.
Save jcroft/792466 to your computer and use it in GitHub Desktop.
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
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'KEY_PREFIX': 'barstar_',
}
}
>>> 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)
>>>
>>> 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)
>>> 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."
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment