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

Cache is saved as disk cache in the browser #674

Closed
juliGer opened this issue Jul 22, 2023 · 3 comments
Closed

Cache is saved as disk cache in the browser #674

juliGer opened this issue Jul 22, 2023 · 3 comments
Labels

Comments

@juliGer
Copy link

juliGer commented Jul 22, 2023

Hello! I wanted to see if this is because of how I am using the cache in django or if I am missing an option in the django-redis config

What I want is for it to be saved in memory and not on disk, that is, when reloading with ctrl + f5, for example, the back response is no longer cached, is it possible?

thank you!

settings.py

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "KEY_PREFIX": 'alfadatizando',
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

CELERY_BROKER_URL = 'redis://127.0.0.1:6379/'
# save Celery task results in Django's database
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/'
# this allows you to schedule items in the Django admin.
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'

DEFAULT_CACHING_TIME = 60 * 60 * 12 

api.py

class EstablishmentViewSet(viewsets.ModelViewSet):
    queryset = Establishment.objects.filter(
        deleted=False)
    helper = EstablishmentHelper
    filterset_class = EstablishmentFilter
    methods_no_authentication = ['list']
    permission_classes = [NoAuthentication]
    ordering = ['name']
    pagination_class = StandardResultsOptionalPagination

    serializers = {
        'default': EstablishmentSerializer,
        'update': EstablishmentUpdateSerializer
    }

    def get_serializer_class(self):
        return self.serializers.get(
            self.action, self.serializers["default"])

    @method_decorator(cache_page(DEFAULT_CACHING_TIME))
    def list(self, request, *args, **kwargs):
        return super().list(request, *args, **kwargs)
@WisdomPill
Copy link
Member

hello @juliGer I am afraid I do not understand your question, could you rephrase please and maybe even send some screenshots?

Also with these kind of question I think you might be luckier in stack overflow as it is not strictly related to a possible issue with the library

@juliGer
Copy link
Author

juliGer commented Jul 23, 2023

hello @WisdomPill ! Here's a question with the same problem I have on stackoverflow

https://stackoverflow.com/questions/69316195/django-rest-framework-still-respond-with-cached-data-even-after-having-empty-red

I tried to do the solution given in the answer but that is to avoid caching, I didn't know if this was happening because of how django works or what it was like.

I leave a picture of how a cached resource looks in the browser network tab, I would like that the endpoint is stored in cache memory and not on disk because being on the client side even if I delete the keys from the redis server is still cached I explain?

Thank you very much, greetings!

image

@WisdomPill
Copy link
Member

closing this since you got answers in stack overflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants