我正在使用Memcached作为我的django应用程序的后端.此代码在正常的django查询中工作正常:
def get_myobj():
cache_key = 'mykey'
result = cache.get(cache_key, None)
if not result:
result = Product.objects.all().filter(draft=False)
cache.set(cache_key, result)
return result
Run Code Online (Sandbox Code Playgroud)
但是当与django-rest-framework api调用一起使用时它不起作用:
class ProductListAPIView(generics.ListAPIView):
def get_queryset(self):
product_list = Product.objects.all()
return product_list
serializer_class = ProductSerializer
Run Code Online (Sandbox Code Playgroud)
我即将尝试提供缓存功能的DRF扩展:
https://github.com/chibisov/drf-extensions
但是github上的构建状态目前正在说"构建失败".
我的应用程序在api调用时非常重读.有没有办法缓存这些电话?
谢谢.