Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbothma opened this issue Feb 4, 2020 · 0 comments

Comments

@jbothma
Copy link

jbothma commented Feb 4, 2020

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant