New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Functions.memoize(Function) #489

Closed
gissuebot opened this Issue Oct 31, 2014 · 7 comments

Comments

Projects
None yet
1 participant
@gissuebot

gissuebot commented Oct 31, 2014

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.

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

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.

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

Original comment posted by kevinb@google.com on 2010-12-08 at 03:25 AM


Exactly.


Status: WontFix

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

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.

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

Original comment posted by wasserman.louis on 2012-04-03 at 03:26 PM


Hmmmm. That suggests two options:

  1. Functions.forCache, or Caches.asFunction, or something like that.
  2. Push users away from this approach in general, as Caches can throw Exceptions and the like, and Function cannot throw exceptions.
@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

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.

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

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.

@gissuebot

This comment has been minimized.

gissuebot commented Oct 31, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment