Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django docker-compose --> memcached not working

I'm trying to setup django (rest framework) with memcached using docker-compose.

To enable caching with the rest framework, I'm using rest_framework_extensions.

docker-compose.yml

django:
  image: python3
  links:
    - database
    - memcached

memcached:
  image: memcached
  ports:
    - "11211:11211"

settings.py

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

viewsets.py

from rest_framework_extensions.cache.mixins import CacheResponseMixin


class JobPublicViewSet(CacheResponseMixin, viewsets.ReadOnlyModelViewSet):
    pass

Here's my problem:

With the above sketched configuration and setup, nothing is cached.

However, if I remove the CACHES entry from the setting, caching is working just fine. Somewhere there seems to be a default setting for local memory cache.

Can you see why my app doesn't pick up memcached for caching?

like image 580
creimers Avatar asked May 20 '16 09:05

creimers


People also ask

How do you use memcached in Django?

Memcached can be used with Django by setting CACHE_BACKEND to memcached://ip:port/. Here ip is the IP address of the Memcached daemon and port is the port on which the Memcached is running.


1 Answers

The oficial docker image has not set a memory size by default, you need use a entrypoint on docker compose

memcached:
   image: memcached
   ports:
     - "11211:11211"
   entrypoint:
    - memcached
    - -m 64
like image 189
Rivenvirus Avatar answered Oct 30 '22 07:10

Rivenvirus