Reputation: 109
I am looking to cache some rarely updated data coming from several related tables in DB (MySQL to be specific). I have tried django ORM queryset caching with the above django apps but have stumbled into some weird behavior with both of them: some of the queries are queried even when they're supposed to be coming from cache like the rest of them.
I am retrieving the data in a set of 6 queries, mixing any of: filter, select_related, prefetch_related (M2M relations), forward and reverse relations. Just data retrieval, no updates. This happens in a dedicated method, which for the purposes of the evaluation, I'm calling twice from a TestCase. (To preempt any potential issues there was no transactions management of any kind in the evaluated method)
What I'm observing is that 3 of the queries were repeated - one a reverse m2m from prefetch_related (while another reverse m2m was cached), and two rather simple reverse manager queries, that maintained that behavior even when changed to ModelName.objects.all() or a filter corresponding to the relation. These last trials that I made looking for some pattern were made only on johnny-cache, which is preferable for my particular scenario because of its invalidation policies. I also tried to modify the method in some general ways, basically shooting in the dark, like remove the offending queries (everything's cached), leave just one of the offending queries(still not cached), changing query order(no change).
Has anybody run into something similar or can offer some explanation?
Upvotes: 1
Views: 187