Skip to content

Commit

Permalink
add the keys of many to many
Browse files Browse the repository at this point in the history
add the keys of the related models if cached to flush in case of update to be flushed
  • Loading branch information
selbieh committed Jul 15, 2020
1 parent 9a290fb commit 913ec32
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions caching/invalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def invalidate_objects(self, objects, is_new_instance=False, model_cls=None):
if (config.CACHE_INVALIDATE_ON_CREATE == config.WHOLE_MODEL and
is_new_instance and model_cls and hasattr(model_cls, 'model_flush_key')):
flush_keys.append(model_cls.model_flush_key())
#add the keys of the related models if cached to flush in case of update
if (config.CACHE_INVALIDATE_ON_CREATE == config.WHOLE_MODEL and
not is_new_instance and model_cls and hasattr(model_cls, 'model_flush_key')):
flush_keys.append(model_cls.model_flush_key())
many_to_many_fields = [field for field in model_cls._meta.many_to_many if
hasattr(field.remote_field.model, 'model_flush_key')]
for k in many_to_many_fields:
flush_keys.append(k.remote_field.model.model_flush_key())
if not obj_keys or not flush_keys:
return
obj_keys, flush_keys = self.expand_flush_lists(obj_keys, flush_keys)
Expand Down

0 comments on commit 913ec32

Please sign in to comment.