【发布时间】:2017-08-23 09:47:45
【问题描述】:
我正在为 caching 我的 API 使用 drf-extension。但它与 cache_response 装饰器没有按预期工作。
它缓存了/api/get-cities/?country=india 的响应。但是当我点击/api/get-cities/?country=usa 时,我得到了相同的响应。
这里是示例代码:
settings.py
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
"KEY_PREFIX": "city"
}
}
REST_FRAMEWORK_EXTENSIONS = {
'DEFAULT_USE_CACHE': 'default',
'DEFAULT_CACHE_RESPONSE_TIMEOUT': 86400,
}
views.py
class GetCities(APIView):
@cache_response()
def get(self, request):
country = request.GET.get("country", "")
return get_cities_function(country)
请帮忙。
【问题讨论】:
标签: python django caching redis drf-extensions