class NoCacheForAuthMiddleware:
    def __init__(self, get_response): self.get_response = get_response
    def __call__(self, request):
        r = self.get_response(request)
        if getattr(request, 'user', None) and request.user.is_authenticated:
            r['Cache-Control'] = 'no-store, no-cache, must-revalidate, private, max-age=0'
            r['Pragma'] = 'no-cache'
            r['X-LiteSpeed-Cache-Control'] = 'no-cache'
        return r
