Python – Django: Should I use LocMemCache caching?

Django: Should I use LocMemCache caching?… here is a solution to the problem.

Django: Should I use LocMemCache caching?

I’m using this QR code generator . There is a specific section in the documentation about caching. I read that LocMemCache should not be used in production. Is the same with these QR codes? Is there a cache that you can recommend, or is this approach appropriate to use smaller pages at the beginning?

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
    'qr-code': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'qr-code-cache',
        'TIMEOUT': 3600
    }
}

QR_CODE_CACHE_ALIAS = 'qr-code'

Solution

The LocMemCache backend uses only one object that is not shared between processes, so it will use a large amount of memory when running in a production environment with multiple workers.

This may be sufficient if you’re just using it for small applications, but keep in mind that the server’s memory needs to be large enough to contain cached values. If you don’t have enough memory on your small VM, the server won’t be able to process responses correctly.

Related Problems and Solutions