I am building a web-app using django channels. I also have a task function which i run periodically ( every 30s) using celery beat. This task function sends data to my web-socket every 30s.
Now, if a consumer joins my channel group, he has to wait for some time until my next data arrives. But what I want is to show the new consumer my previous data, until new one arrives. So i have to cache my previous data somewhere.
What is the correct way to do that? I know using redis but how in django-channels?
2
Answers
It is quite simple.
to append data to cache simply do:
I hope it works for you!.
If you use AsyncConsumer, you should call cache methods with
sync_to_async
wrapper: