Memcached

Settings

  • Sole

    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': '127.0.0.1:11211',
        }
    }
    
  • Multi

    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': [
                '172.19.26.240:11211',
                '172.19.26.242:11211',
            ]
        }
    }
    

BACKEND

  • MemcachedCache

    • Install Binding

      pip install python-memcached
      
  • PyLibMCCache

    • Install Lib

      sudo apt-get install libmemcached-dev  # Ubuntu
      sudo brew install libmemcached         # Mac OS X
      
    • Install Bingding

      pip install pylibmc
      

Usage

  • Basic

    >>> from django.core.cache import cache
    
    >>> cache.set('my_key', 'hello, world!', 30)
    >>> cache.get('my_key')
    'hello, world!'
    

Problems

  • Using python-memcached happens multi server's data outer-sync
  • When List is too large, set/get is too slow
    • Use String replace of List, json.dumps() before set, json.loads() after get

References

[1] [email protected], Django’s cache framework

[2] [email protected], python-memcached — A python memcached client library

[3] [email protected], pylibmc — A Python wrapper around the libmemcached interface from TangentOrg

results matching ""

    No results matching ""