7👍
✅
It seems that Tastypie doesn’t automatically cache lists, tastypie.resources
around line 1027
:
def get_list(self, request, **kwargs):
# ...
# TODO: Uncached for now. Invalidation that works for everyone may be
# impossible.
objects = self.obj_get_list(
request=request, **self.remove_api_resource_names(kwargs))
# ...
, whereas with details (around line 1050
):
def get_detail(self, request, **kwargs):
# ...
try:
obj = self.cached_obj_get(
request=request, **self.remove_api_resource_names(kwargs))
# ...
… note that in the former snippet obj_get_list
is called instead of cached_obj_get_list
. Perhaps overriding get_list
and using cached_obj_get_list
would allow you to use cache here as well?
Now you probably would get output from your class for http://localhost:8000/api/poll/<pk>/?format=json
(detail view) but not for http://localhost:8000/api/poll/?format=json
(list view) by default.
👤kgr
Source:stackexchange.com