chibisov / drf-extensions

DRF-extensions is a collection of custom extensions for Django REST Framework
http://chibisov.github.io/drf-extensions/docs
MIT License
1.47k stars 208 forks source link

None will not cache. #194

Closed mapleflow closed 6 years ago

mapleflow commented 7 years ago

None will not cache. Is it right ?

mapleflow commented 7 years ago
def calculate_cache_key(view_instance, view_method,
                        request, args, kwargs):

    # i want cache only in home page request
    # but now it cache in 'None' key
    # you can see something in 'None' key
    if request.page_url == 'home_page':
        return 'home_page'

class CityView(views.APIView):
    @cache_response(60 * 15, key_func=calculate_cache_key)
    def get(self, request, *args, **kwargs):
        pass

if not response.status_code >= 400 or self.cache_errors:
    # not the key is 'None'
    self.cache.set(key, response, self.timeout)
auvipy commented 7 years ago

i was talking about providing unit and integration test