Skip to main content

Django module that use consul to generate the list of memcached servers

Project description

django-memcached-consul

Django-memcached-consul helps use consul for memcached servers. It will query Consul Health API to get list of servers every time we use the cache.

Usage

The configuration is done in the cache part of local_settings.py in the Django project. Django-memcached-consul use the Django memcached driver so all configuration related to the caching itself should be done like in django memcached.

To use consul you need to use the specific Django-memcached-consul driver: django-consul-memcached.memcached.MemcachedCache

And to provide informations about Consul and the required services:

CONSUL_HOST # The Consul API host
CONSUL_PORT # The Consul API port
CONSUL_SERVICE # The service of the memcached servers in Consul

It is possible and strongly recommended to use a cache for the consul, otherwise an Consul API call will be issued every time we use the cache.

Django-memcached-consul use two layer of cache: the first layer should be short lived (CONSUL_TTL) and is used to cache the list of memcached servers and is retrieved everytime we use the django-consul-memcached driver. The second one is long lived (CONSUL_TTL_ALT) and retrieved when Consul API is unreachable. The name of the cache to be used is set in CONSUL_CACHE and the cache should be preferably a filebased cache to be shared accross all workers.

Example

CACHES = {
    'default': {
        'BACKEND': 'django_memcached_consul.memcached.MemcachedCache',
        'TIMEOUT': 60,
        'CONSUL_TTL': 60,
        # Alt cache will be used if consul is unreachable
        'CONSUL_ALT_TTL': 3600,
        'CONSUL_CACHE': 'consul-memcached',
        'CONSUL_HOST': 'consul.organization.com',
        'CONSUL_PORT': 8500,
        'CONSUL_SERVICE': 'memcached-service',
    },
    'consul-memcached': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/tmp/django_consul_cache',
    }
}

Testing

Testing require memcached and tox.

First you need to run memcached on default configuration (usually at localhost:11211) or you will have to change informations in tests/tests_data/consul_api_health_mock_with_memcached.json).

Then you can run tox at the root of the project to start the tests:

tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_memcached_consul-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file django_memcached_consul-0.1.3.tar.gz.

File metadata

  • Download URL: django_memcached_consul-0.1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for django_memcached_consul-0.1.3.tar.gz
Algorithm Hash digest
SHA256 41e74652d50cc97e7b73b0a5a7babc185e168c2c0d374392cd66a607bdc56fba
MD5 60d0b3c5f6bc20f9b18b78cf8d3131df
BLAKE2b-256 c911b9df39fef24687b45e4c7ffad07d960ba392cdc3957e477ac30183d3ddc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page