{"action":"created","issue":{"url":"https://api.github.com/repos/Suor/django-cacheops/issues/213","repository_url":"https://api.github.com/repos/Suor/django-cacheops","labels_url":"https://api.github.com/repos/Suor/django-cacheops/issues/213/labels{/name}","comments_url":"https://api.github.com/repos/Suor/django-cacheops/issues/213/comments","events_url":"https://api.github.com/repos/Suor/django-cacheops/issues/213/events","html_url":"https://github.com/Suor/django-cacheops/issues/213","id":181396367,"number":213,"title":"Setting for disabling invalidation in CACHEOPS","user":{"login":"chemary","id":1191573,"avatar_url":"https://avatars.githubusercontent.com/u/1191573?v=3","gravatar_id":"","url":"https://api.github.com/users/chemary","html_url":"https://github.com/chemary","followers_url":"https://api.github.com/users/chemary/followers","following_url":"https://api.github.com/users/chemary/following{/other_user}","gists_url":"https://api.github.com/users/chemary/gists{/gist_id}","starred_url":"https://api.github.com/users/chemary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chemary/subscriptions","organizations_url":"https://api.github.com/users/chemary/orgs","repos_url":"https://api.github.com/users/chemary/repos","events_url":"https://api.github.com/users/chemary/events{/privacy}","received_events_url":"https://api.github.com/users/chemary/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-06T12:03:31Z","updated_at":"2016-10-07T09:14:36Z","closed_at":null,"body":"I use django-cacheops for managing MySQL replication lag, so I set **cache_on_save** to avoid fast reads after write to get stale data.\r\nI think it will be handy to be able to disable invalidation in `CACHEOPS` settings to avoid the `ManagerMixin._post_save()` to make and extra query to get the object, this in conjunction with **cache_on_save** makes code cleaner as no `with no_invalidation:' has to be used .\r\n\r\nThere is any drawback doing so?\r\nThis is my suggested implementation\r\n```python\r\nclass ManagerMixin(object):\r\n    ...\r\n    def _pre_save(self, sender, instance, **kwargs):\r\n        # NOTE: it's possible for this to be a subclass, e.g. proxy, without cacheprofile,\r\n        #       but its base having one. Or vice versa.\r\n        cacheprofile = model_profile(instance.__class__)\r\n        no_invalidation_on_save = cacheprofile.get('no_invalidation_on_save') if cacheprofile else False\r\n\r\n        if instance.pk is not None and not (no_invalidation.active or no_invalidation_on_save):\r\n           try:\r\n               _old_objs.__dict__[sender, instance.pk] = sender.objects.get(pk=instance.pk)\r\n           except sender.DoesNotExist:\r\n               pass\r\n```"},"comment":{"url":"https://api.github.com/repos/Suor/django-cacheops/issues/comments/252191116","html_url":"https://github.com/Suor/django-cacheops/issues/213#issuecomment-252191116","issue_url":"https://api.github.com/repos/Suor/django-cacheops/issues/213","id":252191116,"user":{"login":"Suor","id":284103,"avatar_url":"https://avatars.githubusercontent.com/u/284103?v=3","gravatar_id":"","url":"https://api.github.com/users/Suor","html_url":"https://github.com/Suor","followers_url":"https://api.github.com/users/Suor/followers","following_url":"https://api.github.com/users/Suor/following{/other_user}","gists_url":"https://api.github.com/users/Suor/gists{/gist_id}","starred_url":"https://api.github.com/users/Suor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Suor/subscriptions","organizations_url":"https://api.github.com/users/Suor/orgs","repos_url":"https://api.github.com/users/Suor/repos","events_url":"https://api.github.com/users/Suor/events{/privacy}","received_events_url":"https://api.github.com/users/Suor/received_events","type":"User","site_admin":false},"created_at":"2016-10-07T09:14:36Z","updated_at":"2016-10-07T09:14:36Z","body":"First, `cache_on_save` has nothing to do with neither `pre_save` nor invalidation. Second, your patch doesn't prevent invalidation, it prevents one get request and hurts subsequent invalidation.\r\n\r\nWhat are you trying to achieve? Disable invalidation entirely? Or just skip that request? Why?"}}
{"actor":{"display_login":"Suor"}}