{"action":"opened","number":132,"pull_request":{"url":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132","id":215173704,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE1MTczNzA0","html_url":"https://github.com/isaacs/node-lru-cache/pull/132","diff_url":"https://github.com/isaacs/node-lru-cache/pull/132.diff","patch_url":"https://github.com/isaacs/node-lru-cache/pull/132.patch","issue_url":"https://api.github.com/repos/isaacs/node-lru-cache/issues/132","number":132,"state":"open","locked":false,"title":"Added an `initialiserFn` parameter to the 'get' function.","user":{"login":"nickgrealy","id":1669373,"node_id":"MDQ6VXNlcjE2NjkzNzM=","avatar_url":"https://avatars0.githubusercontent.com/u/1669373?v=4","gravatar_id":"","url":"https://api.github.com/users/nickgrealy","html_url":"https://github.com/nickgrealy","followers_url":"https://api.github.com/users/nickgrealy/followers","following_url":"https://api.github.com/users/nickgrealy/following{/other_user}","gists_url":"https://api.github.com/users/nickgrealy/gists{/gist_id}","starred_url":"https://api.github.com/users/nickgrealy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickgrealy/subscriptions","organizations_url":"https://api.github.com/users/nickgrealy/orgs","repos_url":"https://api.github.com/users/nickgrealy/repos","events_url":"https://api.github.com/users/nickgrealy/events{/privacy}","received_events_url":"https://api.github.com/users/nickgrealy/received_events","type":"User","site_admin":false},"body":"Hi all,\r\n\r\nI had a [problem, trying to demultiplex a call chain](https://stackoverflow.com/questions/52290043/javascript-demultiplex-cache-a-promise-function-call), and realised I could solve it using the `lru-cache` with `maxAge` and `promises` - awesome!\r\n\r\nTo that end, I thought the library would benefit from having a `get(key, initialiserFn)` function, so that:\r\n\r\n- the existing `get(key)` signature would behave as per existing functionality\r\n- a user can specify an optional `initialiser` function, to populate the cached value (if not present)\r\n- the `initialiser` function may be an asynchronous/expensive operation/take a long time/be rate limited\r\n- in this way, the `initialiser` is invoked once, and it's response is cached for multiple calls\r\n- this works well,  for `initialiser` functions that return a `Promise`\r\n- if `maxAge` is specified, the value would eventually be evicted\r\n\r\nHere's an actual example I'm using it for (using [`socket.io`](https://socket.io/)):\r\n\r\n**_server.js_**\r\n\r\n```js\r\n// setup an LRU cache (with eviction policy)...\r\nconst PROFILE_CACHE = LRU({ max: 50, maxAge: 1000 * 60 })\r\n\r\n// receives \"lots\" of async requests from a client...\r\nsocket.on('getUserProfileRequest', userId => {\r\n  PROFILE_CACHE.get(userId, () => getUserProfile(userId))\r\n    .then(profile => socket.emit('getUserProfileResponse', profile))\r\n})\r\n\r\n// calls upstream server, does async/expensive/long running work, returns a Promise...\r\nfunction getUserProfile(userId) { /* ... */ }\r\n```","created_at":"2018-09-13T06:07:24Z","updated_at":"2018-09-13T06:07:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132/commits","review_comments_url":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132/comments","review_comment_url":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/comments{/number}","comments_url":"https://api.github.com/repos/isaacs/node-lru-cache/issues/132/comments","statuses_url":"https://api.github.com/repos/isaacs/node-lru-cache/statuses/004b422f9941529ccb874a46ee352c969575f62c","head":{"label":"mountain-pass:master","ref":"master","sha":"004b422f9941529ccb874a46ee352c969575f62c","user":{"login":"mountain-pass","id":12326351,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyMzI2MzUx","avatar_url":"https://avatars2.githubusercontent.com/u/12326351?v=4","gravatar_id":"","url":"https://api.github.com/users/mountain-pass","html_url":"https://github.com/mountain-pass","followers_url":"https://api.github.com/users/mountain-pass/followers","following_url":"https://api.github.com/users/mountain-pass/following{/other_user}","gists_url":"https://api.github.com/users/mountain-pass/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain-pass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain-pass/subscriptions","organizations_url":"https://api.github.com/users/mountain-pass/orgs","repos_url":"https://api.github.com/users/mountain-pass/repos","events_url":"https://api.github.com/users/mountain-pass/events{/privacy}","received_events_url":"https://api.github.com/users/mountain-pass/received_events","type":"Organization","site_admin":false},"repo":{"id":148566847,"node_id":"MDEwOlJlcG9zaXRvcnkxNDg1NjY4NDc=","name":"node-lru-cache","full_name":"mountain-pass/node-lru-cache","owner":{"login":"mountain-pass","id":12326351,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyMzI2MzUx","avatar_url":"https://avatars2.githubusercontent.com/u/12326351?v=4","gravatar_id":"","url":"https://api.github.com/users/mountain-pass","html_url":"https://github.com/mountain-pass","followers_url":"https://api.github.com/users/mountain-pass/followers","following_url":"https://api.github.com/users/mountain-pass/following{/other_user}","gists_url":"https://api.github.com/users/mountain-pass/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain-pass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain-pass/subscriptions","organizations_url":"https://api.github.com/users/mountain-pass/orgs","repos_url":"https://api.github.com/users/mountain-pass/repos","events_url":"https://api.github.com/users/mountain-pass/events{/privacy}","received_events_url":"https://api.github.com/users/mountain-pass/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mountain-pass/node-lru-cache","description":null,"fork":true,"url":"https://api.github.com/repos/mountain-pass/node-lru-cache","forks_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/forks","keys_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/teams","hooks_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/hooks","issue_events_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/issues/events{/number}","events_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/events","assignees_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/assignees{/user}","branches_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/branches{/branch}","tags_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/tags","blobs_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/git/refs{/sha}","trees_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/statuses/{sha}","languages_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/languages","stargazers_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/stargazers","contributors_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/contributors","subscribers_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/subscribers","subscription_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/subscription","commits_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/commits{/sha}","git_commits_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/git/commits{/sha}","comments_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/comments{/number}","issue_comment_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/issues/comments{/number}","contents_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/contents/{+path}","compare_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/merges","archive_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/downloads","issues_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/issues{/number}","pulls_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/pulls{/number}","milestones_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/milestones{/number}","notifications_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/labels{/name}","releases_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/releases{/id}","deployments_url":"https://api.github.com/repos/mountain-pass/node-lru-cache/deployments","created_at":"2018-09-13T01:56:18Z","updated_at":"2018-09-13T04:19:06Z","pushed_at":"2018-09-13T04:19:05Z","git_url":"git://github.com/mountain-pass/node-lru-cache.git","ssh_url":"git@github.com:mountain-pass/node-lru-cache.git","clone_url":"https://github.com/mountain-pass/node-lru-cache.git","svn_url":"https://github.com/mountain-pass/node-lru-cache","homepage":null,"size":274,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"isc","name":"ISC License","spdx_id":"ISC","url":"https://api.github.com/licenses/isc","node_id":"MDc6TGljZW5zZTEw"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"isaacs:master","ref":"master","sha":"9c895c3045b4decf49bbbd7d5171f0be2ff86039","user":{"login":"isaacs","id":9287,"node_id":"MDQ6VXNlcjkyODc=","avatar_url":"https://avatars2.githubusercontent.com/u/9287?v=4","gravatar_id":"","url":"https://api.github.com/users/isaacs","html_url":"https://github.com/isaacs","followers_url":"https://api.github.com/users/isaacs/followers","following_url":"https://api.github.com/users/isaacs/following{/other_user}","gists_url":"https://api.github.com/users/isaacs/gists{/gist_id}","starred_url":"https://api.github.com/users/isaacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isaacs/subscriptions","organizations_url":"https://api.github.com/users/isaacs/orgs","repos_url":"https://api.github.com/users/isaacs/repos","events_url":"https://api.github.com/users/isaacs/events{/privacy}","received_events_url":"https://api.github.com/users/isaacs/received_events","type":"User","site_admin":false},"repo":{"id":679662,"node_id":"MDEwOlJlcG9zaXRvcnk2Nzk2NjI=","name":"node-lru-cache","full_name":"isaacs/node-lru-cache","owner":{"login":"isaacs","id":9287,"node_id":"MDQ6VXNlcjkyODc=","avatar_url":"https://avatars2.githubusercontent.com/u/9287?v=4","gravatar_id":"","url":"https://api.github.com/users/isaacs","html_url":"https://github.com/isaacs","followers_url":"https://api.github.com/users/isaacs/followers","following_url":"https://api.github.com/users/isaacs/following{/other_user}","gists_url":"https://api.github.com/users/isaacs/gists{/gist_id}","starred_url":"https://api.github.com/users/isaacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isaacs/subscriptions","organizations_url":"https://api.github.com/users/isaacs/orgs","repos_url":"https://api.github.com/users/isaacs/repos","events_url":"https://api.github.com/users/isaacs/events{/privacy}","received_events_url":"https://api.github.com/users/isaacs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/isaacs/node-lru-cache","description":null,"fork":false,"url":"https://api.github.com/repos/isaacs/node-lru-cache","forks_url":"https://api.github.com/repos/isaacs/node-lru-cache/forks","keys_url":"https://api.github.com/repos/isaacs/node-lru-cache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/isaacs/node-lru-cache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/isaacs/node-lru-cache/teams","hooks_url":"https://api.github.com/repos/isaacs/node-lru-cache/hooks","issue_events_url":"https://api.github.com/repos/isaacs/node-lru-cache/issues/events{/number}","events_url":"https://api.github.com/repos/isaacs/node-lru-cache/events","assignees_url":"https://api.github.com/repos/isaacs/node-lru-cache/assignees{/user}","branches_url":"https://api.github.com/repos/isaacs/node-lru-cache/branches{/branch}","tags_url":"https://api.github.com/repos/isaacs/node-lru-cache/tags","blobs_url":"https://api.github.com/repos/isaacs/node-lru-cache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/isaacs/node-lru-cache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/isaacs/node-lru-cache/git/refs{/sha}","trees_url":"https://api.github.com/repos/isaacs/node-lru-cache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/isaacs/node-lru-cache/statuses/{sha}","languages_url":"https://api.github.com/repos/isaacs/node-lru-cache/languages","stargazers_url":"https://api.github.com/repos/isaacs/node-lru-cache/stargazers","contributors_url":"https://api.github.com/repos/isaacs/node-lru-cache/contributors","subscribers_url":"https://api.github.com/repos/isaacs/node-lru-cache/subscribers","subscription_url":"https://api.github.com/repos/isaacs/node-lru-cache/subscription","commits_url":"https://api.github.com/repos/isaacs/node-lru-cache/commits{/sha}","git_commits_url":"https://api.github.com/repos/isaacs/node-lru-cache/git/commits{/sha}","comments_url":"https://api.github.com/repos/isaacs/node-lru-cache/comments{/number}","issue_comment_url":"https://api.github.com/repos/isaacs/node-lru-cache/issues/comments{/number}","contents_url":"https://api.github.com/repos/isaacs/node-lru-cache/contents/{+path}","compare_url":"https://api.github.com/repos/isaacs/node-lru-cache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/isaacs/node-lru-cache/merges","archive_url":"https://api.github.com/repos/isaacs/node-lru-cache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/isaacs/node-lru-cache/downloads","issues_url":"https://api.github.com/repos/isaacs/node-lru-cache/issues{/number}","pulls_url":"https://api.github.com/repos/isaacs/node-lru-cache/pulls{/number}","milestones_url":"https://api.github.com/repos/isaacs/node-lru-cache/milestones{/number}","notifications_url":"https://api.github.com/repos/isaacs/node-lru-cache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/isaacs/node-lru-cache/labels{/name}","releases_url":"https://api.github.com/repos/isaacs/node-lru-cache/releases{/id}","deployments_url":"https://api.github.com/repos/isaacs/node-lru-cache/deployments","created_at":"2010-05-21T21:00:58Z","updated_at":"2018-09-12T14:12:45Z","pushed_at":"2018-05-07T23:18:09Z","git_url":"git://github.com/isaacs/node-lru-cache.git","ssh_url":"git@github.com:isaacs/node-lru-cache.git","clone_url":"https://github.com/isaacs/node-lru-cache.git","svn_url":"https://github.com/isaacs/node-lru-cache","homepage":null,"size":270,"stargazers_count":2225,"watchers_count":2225,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":206,"mirror_url":null,"archived":false,"open_issues_count":27,"license":{"key":"isc","name":"ISC License","spdx_id":"ISC","url":"https://api.github.com/licenses/isc","node_id":"MDc6TGljZW5zZTEw"},"forks":206,"open_issues":27,"watchers":2225,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132"},"html":{"href":"https://github.com/isaacs/node-lru-cache/pull/132"},"issue":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/issues/132"},"comments":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/issues/132/comments"},"review_comments":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132/comments"},"review_comment":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/pulls/132/commits"},"statuses":{"href":"https://api.github.com/repos/isaacs/node-lru-cache/statuses/004b422f9941529ccb874a46ee352c969575f62c"}},"author_association":"NONE","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":1,"additions":1689,"deletions":1361,"changed_files":3}}
{"actor":{"display_login":"nickgrealy"}}