drf-haystack icon indicating copy to clipboard operation
drf-haystack copied to clipboard

How would I do view-based caching for FacetMixin and HaystackViewSet views?

Open jbothma opened this issue 6 years ago • 0 comments

I'd like to use django view-based caching to set specific cache times for my .../search and .../search/facets URLs.

How would I go about that with drf-haystack?

I tried the following based on https://www.django-rest-framework.org/api-guide/caching/ but I got errors:

class ProjectSearchViewSet(FacetMixin, HaystackViewSet):
...
    @method_decorator(cache_page(60 * 30))  # minutes
    def get(self, *args, **kwargs):
        super(ProjectSearchView, self).get(*args, **kwargs)

    @method_decorator(cache_page(60 * 30))  # minutes
    def list(self, *args, **kwargs):
        super(ProjectSearchView, self).list(*args, **kwargs)

e.g.

app_1     |   File "/usr/local/lib/python2.7/site-packages/rest_framework/viewsets.py", line 116, in view
app_1     |     return self.dispatch(request, *args, **kwargs)
app_1     |   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 495, in dispatch
app_1     |     response = self.handle_exception(exc)
app_1     |   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 455, in handle_exception
app_1     |     self.raise_uncaught_exception(exc)
app_1     |   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 466, in raise_uncaught_exception
app_1     |     raise exc
app_1     | AttributeError: 'NoneType' object has no attribute 'streaming'

jbothma avatar Feb 04 '20 15:02 jbothma