Skip to content

add the keys of many to many #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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