{"action":"created","issue":{"url":"https://api.github.com/repos/ben-manes/caffeine/issues/54","repository_url":"https://api.github.com/repos/ben-manes/caffeine","labels_url":"https://api.github.com/repos/ben-manes/caffeine/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/ben-manes/caffeine/issues/54/comments","events_url":"https://api.github.com/repos/ben-manes/caffeine/issues/54/events","html_url":"https://github.com/ben-manes/caffeine/issues/54","id":134380992,"number":54,"title":"Agrona Queue Comparison","user":{"login":"nosideeffects","id":2198073,"avatar_url":"https://avatars.githubusercontent.com/u/2198073?v=3","gravatar_id":"","url":"https://api.github.com/users/nosideeffects","html_url":"https://github.com/nosideeffects","followers_url":"https://api.github.com/users/nosideeffects/followers","following_url":"https://api.github.com/users/nosideeffects/following{/other_user}","gists_url":"https://api.github.com/users/nosideeffects/gists{/gist_id}","starred_url":"https://api.github.com/users/nosideeffects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nosideeffects/subscriptions","organizations_url":"https://api.github.com/users/nosideeffects/orgs","repos_url":"https://api.github.com/users/nosideeffects/repos","events_url":"https://api.github.com/users/nosideeffects/events{/privacy}","received_events_url":"https://api.github.com/users/nosideeffects/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-02-17T19:45:22Z","updated_at":"2016-02-18T17:31:13Z","closed_at":"2016-02-18T07:55:13Z","body":"How does your own single consumer queue implementation compare to the two variants in https://github.com/real-logic/Agrona ?"},"comment":{"url":"https://api.github.com/repos/ben-manes/caffeine/issues/comments/185826362","html_url":"https://github.com/ben-manes/caffeine/issues/54#issuecomment-185826362","issue_url":"https://api.github.com/repos/ben-manes/caffeine/issues/54","id":185826362,"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":"2016-02-18T17:31:13Z","updated_at":"2016-02-18T17:31:13Z","body":"Oh! I see. By asynchronous weighing I meant for use by an `AsyncLoadingCache` which holds futures.\r\n\r\nThe weight has to be calculated up front and is computed outside of any atomic blocks. I think you could use a similar scheme based on the same principles (initially zero -> async ->  re-weigh & replace). Then you could use a `ThreadLocal` to observe whether the weigher was called by a user or async thread. I'm thinking something like,\r\n\r\n```java\r\nclass AsyncWeigher<K, V> implements Weigher<K, V> {\r\n  static final ThreadLocal<Boolean> isAsyncThread = ...\r\n\r\n  Cache<K, V> cache;\r\n  final Executor executor = ...\r\n  final Weigher<K, V> delegate = ...\r\n\r\n  @Override public int weigh(K key, V value) {\r\n    if (isAsyncThread.get()) {\r\n      return delegate.weigh(key, value);\r\n    }\r\n    executor.execute(() -> {\r\n      isAsyncThread.set(true);\r\n      cache.asMap().replace(key, value, value);\r\n      isAsyncThread.set(false);\r\n    });\r\n  }\r\n}\r\n\r\nAsyncWeigher<K, V> asyncWeigher = AsyncWeigher.of(expensiveWeigher, ...);\r\nCache<String, Object> cache = Caffeine.newBuilder()\r\n        .maximumWeight(MAX_WEIGHT)\r\n        .weigher(asyncWeigher)\r\n        .build();\r\nasyncWeigher.setCache(cache);\r\n```"}}