DRF缓存的补充--Caching errors

Caching errors

以下来自于翻译
默认情况,请求遇到错误时候,下一次还是会返回缓存的错误,例如:

class CityView(views.APIView):
    @cache_response()
    def get(self, request, *args, **kwargs):
        raise Exception("500 error comes from here")

需要改变这种状况时,可以在装饰器中指明cache_errors=False

class CityView(views.APIView):
    @cache_response(cache_errors=False)
    def get(self, request, *args, **kwargs):
        raise Exception("500 error comes from here")

也可以修改DEFAULT_CACHE_ERRORS的设置

REST_FRAMEWORK_EXTENSIONS = {
    'DEFAULT_CACHE_ERRORS': False
}

猜你喜欢

转载自blog.csdn.net/wu0che28/article/details/81501721
今日推荐