Sunday, November 13, 2022

[FIXED] How to use memcached in django project?

Issue

I am working on django-project ,I want to reduce database request overhead. So I am trying with django-cache (Requires Memcached)

vi /etc/sysconfig/memcached

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64" We increased memory size up to 256
OPTIONS="" added IP address "-l 127.0.0.1" 

Changes settings as follows in project:Added new variable in settings.py

CACHE_BACKEND='memcached://localhost:11211'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

[ Note : restart memcached: /etc/init.d/memcached restart]

Project is working, It reduces the database request overhead: but that brings certain issues: I lost my session after few time. So I need to login again in application,how can I handle this,I want to store only session details.


Solution

You are using it correctly but keep in mind that if you restart memcached, you will loose all your existing sessions. That's to be expected.



Answered By - sorin
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.