[Fixed]-Can not cache queryset in Django

1๐Ÿ‘

โœ…

I figured out what caused this: memcache hash value can not be larger than 1mb.
So I switched to redis, and the problem was gone:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

IMPORTANT: make sure that redis version is 2.6 or higher.
redis-server --version
In older versions of redis, apparently redis does not recognize key timeout parameter and throughs error. This tripped me a while because the default redis on Debian 7 was 2.4.

๐Ÿ‘คJand

Leave a comment