I’m working on an app that requires me to filter through large amount of records. I’ve been reading about caching QuerySets and related stuff and found some good material.
qs = MyModel.objects.filter(Q(<initial_filter_to_narrow_down_size>))
After this, I wish to put this qs in cache for later use. I want to apply all the other filters without hitting the database. something like
cache.set('qs', qs)
but what happens when I will do qs = qs.filter(q_object) ? Cache will be modified ? I don’t want that. I want qs to remain constant until I update it. What should I do in this case ?
.filter() clones the queryset before applying the filter. Cache will not be affected.
BTW, you might want to check JohnnyCache … a great app about queryset caching.