{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/airmozilla/issues/156","labels_url":"https://api.github.com/repos/mozilla/airmozilla/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/airmozilla/issues/156/comments","events_url":"https://api.github.com/repos/mozilla/airmozilla/issues/156/events","html_url":"https://github.com/mozilla/airmozilla/pull/156","id":52858411,"number":156,"title":"Bug#1115451- Cache invalidation for deleting pictures","user":{"login":"anurag90x","id":1813816,"avatar_url":"https://avatars.githubusercontent.com/u/1813816?v=3","gravatar_id":"","url":"https://api.github.com/users/anurag90x","html_url":"https://github.com/anurag90x","followers_url":"https://api.github.com/users/anurag90x/followers","following_url":"https://api.github.com/users/anurag90x/following{/other_user}","gists_url":"https://api.github.com/users/anurag90x/gists{/gist_id}","starred_url":"https://api.github.com/users/anurag90x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anurag90x/subscriptions","organizations_url":"https://api.github.com/users/anurag90x/orgs","repos_url":"https://api.github.com/users/anurag90x/repos","events_url":"https://api.github.com/users/anurag90x/events{/privacy}","received_events_url":"https://api.github.com/users/anurag90x/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-12-25T10:37:23Z","updated_at":"2015-01-05T19:46:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mozilla/airmozilla/pulls/156","html_url":"https://github.com/mozilla/airmozilla/pull/156","diff_url":"https://github.com/mozilla/airmozilla/pull/156.diff","patch_url":"https://github.com/mozilla/airmozilla/pull/156.patch"},"body":"When a picture is deleted the get_all_pictures key is removed from the cache but any event associated with the picture has the key as get_all_pictures+event.id in the cache. That's why the reference still persists. To rectify that, before rendering the page just check whether  the result from trying to get 'get_all_pictures' is the same as the result from the 'get_all_pictures+event.id' case. If it is, wonderful else something happened (this could be that the picture was deleted or a new picture was added or both happened, one after the other. In this case always go to the db and reset the cache values).\r\n\r\nThe test is only for the case mentioned in the bug."},"comment":{"url":"https://api.github.com/repos/mozilla/airmozilla/issues/comments/68764558","html_url":"https://github.com/mozilla/airmozilla/pull/156#issuecomment-68764558","issue_url":"https://api.github.com/repos/mozilla/airmozilla/issues/156","id":68764558,"user":{"login":"anurag90x","id":1813816,"avatar_url":"https://avatars.githubusercontent.com/u/1813816?v=3","gravatar_id":"","url":"https://api.github.com/users/anurag90x","html_url":"https://github.com/anurag90x","followers_url":"https://api.github.com/users/anurag90x/followers","following_url":"https://api.github.com/users/anurag90x/following{/other_user}","gists_url":"https://api.github.com/users/anurag90x/gists{/gist_id}","starred_url":"https://api.github.com/users/anurag90x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anurag90x/subscriptions","organizations_url":"https://api.github.com/users/anurag90x/orgs","repos_url":"https://api.github.com/users/anurag90x/repos","events_url":"https://api.github.com/users/anurag90x/events{/privacy}","received_events_url":"https://api.github.com/users/anurag90x/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T19:46:02Z","updated_at":"2015-01-05T19:46:02Z","body":"@peterbe I agree. I think my fix takes care of this case but it just adds to the overall confusion when reading the code. When I looked at the code, I was wondering why there would be so much caching involved for getting the pictures , with the different cache keys and all. I think just having a key for all_pictures is enough. So if the request is for no particular event (/picturegallery), use previous cache result to display the data or if it's the first time then insert into cache, and if it's for an event (/picturegallery/?event=<event_id>), then just get the relevant results from the database without involving any additional caching.\r\n\r\nI'd be happy to fix this in a new bug. :smile: "}}