Feature request: Functions.memoize(Function) #489
Comments
Original comment posted by cgdecker on 2010-11-30 at 03:18 PM Use MapMaker to create a computing map with the behavior you want, then create a Function based on that with Functions.forMap. |
Original comment posted by kevinb@google.com on 2010-12-08 at 03:25 AM Exactly. Status: |
Original comment posted by pimlottc on 2012-04-03 at 03:19 PM In light of the changes to MapMaker.makeComputerMap, I think this issue should be revisited. The original suggestion: Functions.forMap(new MapMaker().makeComputingMap(someFunction)); is now deprecated. Naively following the MapMaker Migration Guide suggests: Functions.forMap(CacheBuilder.newBuilder().build(CacheLoader.from(someFunction)).asMap()); But this does not work as expected, as get() on the map view does not trigger cache loads. |
Original comment posted by wasserman.louis on 2012-04-03 at 03:26 PM Hmmmm. That suggests two options:
|
Original comment posted by cpovirk@google.com on 2012-04-03 at 03:27 PM You can get the original behavior with "CacheBuilder.newBuilder().build(CacheLoader.from(someFunction)," as LoadingCache implements Function. This is still messier than the original, but Function isn't typically used for heavyweight operations, so a little verbosity is probably OK for the cases in which it is. |
Original comment posted by wasserman.louis on 2012-04-03 at 03:37 PM Oh man, I totally forgot that LoadingCache implements Function. That works just fine, then. |
Original comment posted by kevinb@google.com on 2012-04-03 at 09:58 PM Plus, in many cases, you can just implement CacheLoader in the first place instead of Function. |
Original issue created by yogy.namara on 2010-11-30 at 06:08 AM
Just like Suppliers.memoize(Supplier). Consider also adding the expiration-dated variant.
The text was updated successfully, but these errors were encountered: