4

ビューセットに drf-extensions から CacheResponseMixin を追加しましたが、最初のページのみがキャッシュされ、他のすべてのページに対して返されます。たとえば、/?page=2 は単にページ 1 の結果を返します。

class ProductViewSet(CacheResponseMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = Product.objects.filter(withdrawn=False)
    serializer_class = ProductSerializer
    pagination_class = LargeResultsSetPagination

私はジャンゴ1.85を使用しています。これはバグですか、何か不足していますか?

4

2 に答える 2

0

カスタム キー コンストラクターを使用した最終的な修正:

from rest_framework_extensions.cache.mixins import CacheResponseMixin
from rest_framework_extensions.key_constructor.constructors import (
    DefaultKeyConstructor
)
from rest_framework_extensions.key_constructor.bits import (
    QueryParamsKeyBit   
)

class QueryParamsKeyConstructor(DefaultKeyConstructor):
    all_query_params = bits.QueryParamsKeyBit()

class ProductViewSet(CacheResponseMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = Product.objects.filter(withdrawn=False)
    serializer_class = ProductSerializer
    pagination_class = LargeResultsSetPagination
    list_cache_key_func = QueryParamsKeyConstructor()
于 2016-08-30T09:20:33.993 に答える