0

We have been working with Django and Django RestFramework for quite a time now and facing a lot of challenging to manage cache in Redis, our models look like

(1) School (Details of School)

(2) Teacher (FK School, with all details of teacher)

(3) Student (FK Teacher, with all details of Teacher)

Our users would be operating CRUD operation on School, like /get_all_info should return a JSON object like,

{
 "name": "something"
 "teachers": [
   {
     "name": "teacher1 name",
      "students": [
         {
            "name" : "student1 name"
         }, ... all students of that teacher
      ]
    }, ... all teacher of that school
 ]
}

Also, the whole system is very dynamic, each component keeps on changing. Around 90% of requests are of the type stated above.

We were thinking of adding post-save signals to delete full cache each time for the school like a student is updated in post-save first we will find his-her school then delete cache for that school. Is there is some more elegant/better approach? Is there any python library that can handle all this?

  • I think it's fine what you want to build. If you think your data is changing so rapidly that you can't cache your queries then what you plan to achieve with signals is fine. And there shouldn't be a problem. But you will have to analyse and set your TTL carefully so that caching the results really improve your performance. – Sadan A. Jun 30 '21 at 21:27
  • @SadanA. it becomes really hard to main, and need to add code in each postsave – Nivedit Jain Jul 07 '21 at 12:37
  • How are you deleting the cache? and testing if its serving cached data or a fresh data from database – Ryan Aquino Sep 20 '21 at 02:49

0 Answers0