I am new to Django. I was trying to implement Redis cache system into my Django project. I am using AWS free tier to host my Django project on EC2 machine using gunicorn web server and trying to integrate AWS Redis Cache. I have added below entry in my settings.py file:
CACHE = {
'default': {
'BACKEND' : "redis_cache.cache.RedisCache",
'LOCATION' : "redis://xxx.xxx.xxxxx.cache.amazonaws.com/1",
'OPTIONS' : {
'CLIENT_CLASS' : 'redis_cache.client.DefaultClient',
},
}
}
And below is my view function:
def usertable(request):
obj = userdetails.objects.get(id=1)
name = obj.name
if cache.get(name):
cache_name = cache.get(name)
print ("From CACHE")
else:
cache_name = obj.name
cache.set(name, cache_name)
print ("*****************FROM DB********************")
context = {
'name' : cache_name,
}
This code is working for me and I can see From CACHE printed in my terminal. But the key value pair which is set if I manually connect to redis using below cli tool:
redis-cli -h xx.xx.xxxxx…cache.amazonaws.com -p 6379 -n 1
on giving keys * I do not see any key value pair is set.
I am not sure if this is the correct way to test integration of Redis cache. Kindly advice if anyone had tried Redis Cache system.