{"action":"created","issue":{"url":"https://api.github.com/repos/karlseguin/ccache/issues/16","repository_url":"https://api.github.com/repos/karlseguin/ccache","labels_url":"https://api.github.com/repos/karlseguin/ccache/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/karlseguin/ccache/issues/16/comments","events_url":"https://api.github.com/repos/karlseguin/ccache/issues/16/events","html_url":"https://github.com/karlseguin/ccache/pull/16","id":341591189,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxNjkyOTg1","number":16,"title":"Support for OnDelete() callback","user":{"login":"alexejk","id":104794,"node_id":"MDQ6VXNlcjEwNDc5NA==","avatar_url":"https://avatars1.githubusercontent.com/u/104794?v=4","gravatar_id":"","url":"https://api.github.com/users/alexejk","html_url":"https://github.com/alexejk","followers_url":"https://api.github.com/users/alexejk/followers","following_url":"https://api.github.com/users/alexejk/following{/other_user}","gists_url":"https://api.github.com/users/alexejk/gists{/gist_id}","starred_url":"https://api.github.com/users/alexejk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexejk/subscriptions","organizations_url":"https://api.github.com/users/alexejk/orgs","repos_url":"https://api.github.com/users/alexejk/repos","events_url":"https://api.github.com/users/alexejk/events{/privacy}","received_events_url":"https://api.github.com/users/alexejk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-16T16:34:21Z","updated_at":"2018-07-19T04:46:13Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/karlseguin/ccache/pulls/16","html_url":"https://github.com/karlseguin/ccache/pull/16","diff_url":"https://github.com/karlseguin/ccache/pull/16.diff","patch_url":"https://github.com/karlseguin/ccache/pull/16.patch"},"body":"While using this cache i've hit a block where I needed to ensure the item being removed from the cache stops its internal go-routine (basically a `Close()`). Without closing the resources - cached items will never be cleared by GC.\r\n\r\nThis PR allows doing just that by registering a callback for removal via `Configuration.OnRemove()`.\r\n\r\nFor example:\r\n```go\r\n// MyCloseable is a sample Item we will put in cache that might need more cleanup\r\ntype MyCloseable struct{}\r\nfunc NewCloseable() *MyCloseable{\r\n  c := &MyCloseable{}\r\n  // Do something else, such as start go routines\r\n\r\n  return c\r\n}\r\nfunc (c *MyCloseable) Close() {\r\n  // Clean-up resources, e.g stop go routines\r\n}\r\n\r\n---\r\n\r\n// Support function that will be used as a callback\r\nfunc cleanupCloseable(item *ccache.Item) {\r\n\r\n  // Do something to cleanup, e.g call Close()\r\n  closeable := item.Value().(*MyCloseable)\r\n  closeable.Close()\r\n}\r\n\r\nfunc main() {\r\n  c := ccache.New(Configure().OnDelete(cleanupCloseable))\r\n  c.Set(\"one\", NewCloseable())\r\n\r\n  // After some time ...\r\n  c.Delete(\"one\")\r\n}\r\n```\r\n\r\nTests are updated to ensure function is called on both layered cache and standard impl.\r\n\r\nAdditionally as part of this PR I've made it `dep`-friendly by supporting vendoring and locking versions to ensure proper dependency management. https://github.com/golang/dep\r\n"},"comment":{"url":"https://api.github.com/repos/karlseguin/ccache/issues/comments/406153320","html_url":"https://github.com/karlseguin/ccache/pull/16#issuecomment-406153320","issue_url":"https://api.github.com/repos/karlseguin/ccache/issues/16","id":406153320,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjE1MzMyMA==","user":{"login":"karlseguin","id":206480,"node_id":"MDQ6VXNlcjIwNjQ4MA==","avatar_url":"https://avatars3.githubusercontent.com/u/206480?v=4","gravatar_id":"","url":"https://api.github.com/users/karlseguin","html_url":"https://github.com/karlseguin","followers_url":"https://api.github.com/users/karlseguin/followers","following_url":"https://api.github.com/users/karlseguin/following{/other_user}","gists_url":"https://api.github.com/users/karlseguin/gists{/gist_id}","starred_url":"https://api.github.com/users/karlseguin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlseguin/subscriptions","organizations_url":"https://api.github.com/users/karlseguin/orgs","repos_url":"https://api.github.com/users/karlseguin/repos","events_url":"https://api.github.com/users/karlseguin/events{/privacy}","received_events_url":"https://api.github.com/users/karlseguin/received_events","type":"User","site_admin":false},"created_at":"2018-07-19T04:46:13Z","updated_at":"2018-07-19T04:46:13Z","author_association":"OWNER","body":"Feature sounds reasonable, I'll look at the PR in detail this weekend."}}
{"actor":{"display_login":"karlseguin"}}