{"action":"created","issue":{"url":"https://api.github.com/repos/google/guava/issues/1984","labels_url":"https://api.github.com/repos/google/guava/issues/1984/labels{/name}","comments_url":"https://api.github.com/repos/google/guava/issues/1984/comments","events_url":"https://api.github.com/repos/google/guava/issues/1984/events","html_url":"https://github.com/google/guava/pull/1984","id":59579420,"number":1984,"title":"Add a weight() method to Cache","user":{"login":"cheddar","id":216778,"avatar_url":"https://avatars.githubusercontent.com/u/216778?v=3","gravatar_id":"","url":"https://api.github.com/users/cheddar","html_url":"https://github.com/cheddar","followers_url":"https://api.github.com/users/cheddar/followers","following_url":"https://api.github.com/users/cheddar/following{/other_user}","gists_url":"https://api.github.com/users/cheddar/gists{/gist_id}","starred_url":"https://api.github.com/users/cheddar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cheddar/subscriptions","organizations_url":"https://api.github.com/users/cheddar/orgs","repos_url":"https://api.github.com/users/cheddar/repos","events_url":"https://api.github.com/users/cheddar/events{/privacy}","received_events_url":"https://api.github.com/users/cheddar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/guava/labels/cla:%20no","name":"cla: no","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-03T01:05:37Z","updated_at":"2015-03-12T22:30:25Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/google/guava/pulls/1984","html_url":"https://github.com/google/guava/pull/1984","diff_url":"https://github.com/google/guava/pull/1984.diff","patch_url":"https://github.com/google/guava/pull/1984.patch"},"body":"Cache objects currently do not have a method of introspecting on the current \"weight\" value.  I am replacing an implementation of a cache that is just a synchronized LinkedHashMap.  In my current implementation of the cache, I'm keeping track of the weights of things being stored and exposing that as a metric about my cache.  This is the *only* feature of my current implementation that is not covered by Guava's Cache.\r\n\r\nFrom looking at the code, it seemed relatively easy to just create another method parallel to `size()` to handle this case so I just went ahead and did it.  The guidelines do state that API changes should start as an issue, but I didn't realize that until I had already done this and it is such a simple fix, it doesn't bother me if it gets thrown away (as long as I do get some method of introspecting on the current weight value ;) ).\r\n\r\nI do realize that this is a public API change, it is only an addition, but it does mean that if anyone else is implementing the Cache interface from scratch, their code will have to be updated before it can work with this.  I'm not sure what level of API compatibility is maintained with Guava, but as long as people are only using Guava-built cache objects, it should be a forward-compatible change.\r\n\r\nAlso, I updated unit tests as I could find ones that seemed relevant, but I will admit that I didn't read and comprehend all tests, so I might've missed a good place to add some more verification of the weight computation.  Let me know if there are other tests to update and I'll be happy to.\r\n\r\nIf you think this is going to work, let me know and I'll make sure to get a CLA."},"comment":{"url":"https://api.github.com/repos/google/guava/issues/comments/78659937","html_url":"https://github.com/google/guava/pull/1984#issuecomment-78659937","issue_url":"https://api.github.com/repos/google/guava/issues/1984","id":78659937,"user":{"login":"ben-manes","id":378614,"avatar_url":"https://avatars.githubusercontent.com/u/378614?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-manes","html_url":"https://github.com/ben-manes","followers_url":"https://api.github.com/users/ben-manes/followers","following_url":"https://api.github.com/users/ben-manes/following{/other_user}","gists_url":"https://api.github.com/users/ben-manes/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-manes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-manes/subscriptions","organizations_url":"https://api.github.com/users/ben-manes/orgs","repos_url":"https://api.github.com/users/ben-manes/repos","events_url":"https://api.github.com/users/ben-manes/events{/privacy}","received_events_url":"https://api.github.com/users/ben-manes/received_events","type":"User","site_admin":false},"created_at":"2015-03-12T22:30:25Z","updated_at":"2015-03-12T22:30:25Z","body":"I'm offering it as an option as your changes may not be accepted and you would have to wait for the next release if they are. If all you need are the basic features of its predecessor, then its a reasonable option. The old wiki is in the Github wiki branch since the migration didn't move it over properly."}}