{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/53658046","id":53658046,"diff_hunk":"@@ -19,3 +19,18 @@ const handler = new SyncHandler( wpcomXHRHandler );\n // create wpcom instance passing the wrapped handler\n const wpcom = wpcomUndocumented( handler );\n ```\n+\n+### Cache Invalidation\n+\n+`cache-invalidation` attempts cleanup the obsolete records from the local storage of the browser so thus reduce the dB size. The current criteria are two:\n+\n+### syncHandler#pruneRecordsFrom( [lifetime] );\n+Prune records older than the given `lifetime`. By default the value of the lifetime is `2 days`.","path":"client/lib/wp/sync-handler/README.md","position":10,"original_position":10,"commit_id":"130263f72bda02909c8cf7aecf1bb01f7f62f299","original_commit_id":"130263f72bda02909c8cf7aecf1bb01f7f62f299","user":{"login":"gwwar","id":1270189,"avatar_url":"https://avatars.githubusercontent.com/u/1270189?v=3","gravatar_id":"","url":"https://api.github.com/users/gwwar","html_url":"https://github.com/gwwar","followers_url":"https://api.github.com/users/gwwar/followers","following_url":"https://api.github.com/users/gwwar/following{/other_user}","gists_url":"https://api.github.com/users/gwwar/gists{/gist_id}","starred_url":"https://api.github.com/users/gwwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwwar/subscriptions","organizations_url":"https://api.github.com/users/gwwar/orgs","repos_url":"https://api.github.com/users/gwwar/repos","events_url":"https://api.github.com/users/gwwar/events{/privacy}","received_events_url":"https://api.github.com/users/gwwar/received_events","type":"User","site_admin":false},"body":"Add a note that this is in ms?","created_at":"2016-02-22T17:17:24Z","updated_at":"2016-02-22T17:17:24Z","html_url":"https://github.com/Automattic/wp-calypso/pull/3327#discussion_r53658046","pull_request_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327","_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/53658046"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/3327#discussion_r53658046"},"pull_request":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327","id":59428331,"html_url":"https://github.com/Automattic/wp-calypso/pull/3327","diff_url":"https://github.com/Automattic/wp-calypso/pull/3327.diff","patch_url":"https://github.com/Automattic/wp-calypso/pull/3327.patch","issue_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/3327","number":3327,"state":"open","locked":false,"title":"sync-handler: add cache-invalidation process","user":{"login":"retrofox","id":77539,"avatar_url":"https://avatars.githubusercontent.com/u/77539?v=3","gravatar_id":"","url":"https://api.github.com/users/retrofox","html_url":"https://github.com/retrofox","followers_url":"https://api.github.com/users/retrofox/followers","following_url":"https://api.github.com/users/retrofox/following{/other_user}","gists_url":"https://api.github.com/users/retrofox/gists{/gist_id}","starred_url":"https://api.github.com/users/retrofox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/retrofox/subscriptions","organizations_url":"https://api.github.com/users/retrofox/orgs","repos_url":"https://api.github.com/users/retrofox/repos","events_url":"https://api.github.com/users/retrofox/events{/privacy}","received_events_url":"https://api.github.com/users/retrofox/received_events","type":"User","site_admin":false},"body":"### First approach\r\nIt's the first step to start to control the data that are stored locally by `sync-handler` layer. Issue #3281. The idea here is find a way to discard those obsolete records reducing the amount of stored data.\r\n\r\nIn short every time that a new record is added we also add a new item into a `records-list` array which is stored locally as well. This item has the record `key` value and a `marktime` (now).\r\nIn this way we'll have a trace history of all of the resources that we are using to sync the remote data.\r\n\r\nThe `records-list` array has this follow form:\r\n\r\n```js\r\n[\r\n  { key: 'sync-record-<SHA1-hash>', timemark: Date object instance },\r\n  // ...\r\n]\r\n```\r\n\r\n\r\nOnce we have a filled `record-list` array we can start to prune some records depending of our needs. Specifically in this PR I've added `pruneRecordsFrom( lifetime )` method to syncHandler.\r\n\r\n```es6\r\nimport syncHandler from 'lib/wp/sync-handler';\r\n\r\n// prune records from yesterday\r\nlet oneDay = 1000 * 60 * 60 * 24;\r\nsyncHandler.pruneRecordsFrom( oneDay  );\r\n```\r\n\r\nThis method is called in the boot process but we can move it to another place, run it frequently in an interval instance, etc.\r\n\r\n### syncHandler changes\r\n\r\n* add `sync-handler` prefix to records key name. In this way we can identify the records among the whole stored data.\r\n\r\n### Testing\r\n\r\nFirst of all you have to get data stored locally. For that purpose just go to some page that is already being synced:\r\n  * posts list page (`http://calypso.localhost:3000/posts/my/<your-blog>`)\r\n  * settings page (`http://calypso.localhost:3000/me`)\r\n\r\nYou can see how the data is stored setting `localStorage.debug = 'calypso:sync-handler*` in the browser console.\r\n\r\n****\r\n![image](https://cloud.githubusercontent.com/assets/77539/13188765/4015474a-d732-11e5-8770-36c3074b9af8.png)\r\n\r\nAlso you can see the stored data opening `Resources` tab in the Developer Tools -> IndexedDB section:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/77539/13188779/551d818e-d732-11e5-85f9-75a1cc8ca429.png)\r\n\r\nAs I said above the data is _pruned_ in the boot process, so once you have data stored locally make a hard refresh and pay attention how some records are removed (watching debug lines in the console or the `Resources` tab)\r\n\r\n### Expose syncHandler testing object (dev env)\r\n\r\nOne useful thing to test/debug is have a global variable with which we can call some syncHandler methods. It's worth clarify that this var is only exposed in development environment.\r\nSo for instance if you wanna prune those records older than 1 minute just make `syncHandler.pruneRecordsFrom( 60 * 1000 )`:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/77539/13188791/63c554b4-d732-11e5-817d-2d7cb400f1c7.png)\r\n\r\nAlso you can make `syncHandler.clean()` (hard way) to clean whole sync-handler data from local storing:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/77539/13188938/3a09aae8-d733-11e5-8605-a6e122d8b2db.png)","created_at":"2016-02-16T00:18:47Z","updated_at":"2016-02-22T17:17:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2bf33cccf70f438aa9998d9bedb3563085039e32","assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/wp-calypso/milestones/57","html_url":"https://github.com/Automattic/wp-calypso/milestones/Calypso%20Core:%20Offline%205","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones/57/labels","id":1589015,"number":57,"title":"Calypso Core: Offline 5","description":"","creator":{"login":"rralian","id":134044,"avatar_url":"https://avatars.githubusercontent.com/u/134044?v=3","gravatar_id":"","url":"https://api.github.com/users/rralian","html_url":"https://github.com/rralian","followers_url":"https://api.github.com/users/rralian/followers","following_url":"https://api.github.com/users/rralian/following{/other_user}","gists_url":"https://api.github.com/users/rralian/gists{/gist_id}","starred_url":"https://api.github.com/users/rralian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rralian/subscriptions","organizations_url":"https://api.github.com/users/rralian/orgs","repos_url":"https://api.github.com/users/rralian/repos","events_url":"https://api.github.com/users/rralian/events{/privacy}","received_events_url":"https://api.github.com/users/rralian/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":4,"state":"open","created_at":"2016-02-17T17:33:09Z","updated_at":"2016-02-19T22:52:00Z","due_on":"2016-02-23T06:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327/commits","review_comments_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327/comments","review_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/3327/comments","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/130263f72bda02909c8cf7aecf1bb01f7f62f299","head":{"label":"Automattic:update/sync-handler-old-useless-records","ref":"update/sync-handler-old-useless-records","sha":"130263f72bda02909c8cf7aecf1bb01f7f62f299","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-02-22T15:16:39Z","pushed_at":"2016-02-22T17:15:19Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":55267,"stargazers_count":6845,"watchers_count":6845,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":788,"mirror_url":null,"open_issues_count":1252,"forks":788,"open_issues":1252,"watchers":6845,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"9ae0b11cac8ad996425f9a4e51bd4aee7e6eca0d","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-02-22T15:16:39Z","pushed_at":"2016-02-22T17:15:19Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":55267,"stargazers_count":6845,"watchers_count":6845,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":788,"mirror_url":null,"open_issues_count":1252,"forks":788,"open_issues":1252,"watchers":6845,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/3327"},"issue":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/3327"},"comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/3327/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327/comments"},"review_comment":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3327/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/wp-calypso/statuses/130263f72bda02909c8cf7aecf1bb01f7f62f299"}}}}