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?
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.
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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With