你可以重寫功能get_list
在tastypie.resources.ModelResource
更改代碼objects = self.obj_get_list(bundle=base_bundle,**self.remove_api_resource_names(kwargs))
到objects=self.cached_obj_get_list(bundle=base_bundle,**self.remove_api_resource_names(kwargs))
def get_list(self, request, **kwargs):
base_bundle = self.build_bundle(request=request)
objects = self.cached_obj_get_list(bundle=base_bundle, **self.remove_api_resource_names(kwargs))
sorted_objects = self.apply_sorting(objects, options=request.GET)
paginator = self._meta.paginator_class(request.GET, sorted_objects, resource_uri=self.get_resource_uri(), limit=self._meta.limit, max_limit=self._meta.max_limit, collection_name=self._meta.collection_name)
to_be_serialized = paginator.page()
# Dehydrate the bundles in preparation for serialization.
bundles = []
for obj in to_be_serialized[self._meta.collection_name]:
bundle = self.build_bundle(obj=obj, request=request)
bundles.append(self.full_dehydrate(bundle, for_list=True))
to_be_serialized[self._meta.collection_name] = bundles
to_be_serialized = self.alter_list_data_to_serialize(request, to_be_serialized)
return self.create_response(request, to_be_serialized)
然後/ API/REST /提示/將得到緩存,不僅/ API/REST /尖端/ < TIP_ID>/
這是否消息有followups?不能相信沒有任何興趣...... – tutuca
從未有過後續行動。我相信,隨着緩存任意查詢無效的問題幾乎是不可能的,所以它不處理。如果您只使用特定的查詢,你就必須自己手動處理的緩存失效。 – dragonx