I'm using memcached in Django to cache the entire site.
https://docs.djangoproject.com/en/1.11/topics/cache/#the-per-site-cache
I've added some code in a post-save signal handler method to clear the cache when certain objects are created or updated in the model.
from proximity.models import Advert
# Cache
from django.core.cache import cache
@receiver(post_save, sender=Advert)
def save_advert(sender, instance, **kwargs):
# Clear cache
cache.clear()
Unfortunately now after creating a new object, the user is logged out.
I think that the reason can be that I'm caching sessions.
# Cache config
CACHE_MIDDLEWARE_SECONDS = 31449600 #(approximately 1 year, in seconds)
CACHE_MIDDLEWARE_KEY_PREFIX = COREAPP
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
"LOCATION": "127.0.0.1:11211",
}
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
Should I use per-view cache maybe?