Django 3.2.10 Per-site Cache does not refresh after data changes

My middleware order goes like this,

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'UsersUI.middleware.MultitenantMiddleware', #This does not change anything except setting a variable called current tenant from request.user and just returns the self.get_response(request) from __call__ method
]

My cache settings are

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'my_cache_table',
    }
}

CACHE_MIDDLEWARE_SECONDS = 1000000
CACHE_MIDDLEWARE_KEY_PREFIX = ''

Yes, I have created the cache table as well. Even if I do a hard reload and clear the browser cache, the data does not get updated. I need to clear the entire cache table for the change to reflect in the cache. I don't know what went wrong. I am just using a per-site cache.

Also, I don't know if this is relevant, I low-level cached a permission value like this

from django.core.cache import cache
class CheckActiveSubscription(permissions.BasePermission):
    message = "You don't have an active subscription. Please click here {link} to subscribe."
    def has_permission(self, request, view):
        cache_name = str(request.user.firm.firm_code)+str("permission_cache")
        cache_value = cache.get(cache_name)
        if cache_value:
            # not None and It is True
            return cache_value
        else:
            customer = request.user.firm if not request.user.is_anonymous else None
            if customer :
                print("Customer Exists")
                active_plan = customer.check_permission_stripe_MetaProducts
                if active_plan and active_plan in view.allowed_subscriptions:
                    cache.set(cache_name, True, get_expiring_seconds())#expires at 4 am everyday
                    return True
            return False

I remember the cache getting updated even after data change before, now idk what went wrong. Can somebody guide me??

Back to Top