Skip to content
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

[Request] Add large cache option #1

Open
cadaniel opened this issue May 3, 2021 · 2 comments
Open

[Request] Add large cache option #1

cadaniel opened this issue May 3, 2021 · 2 comments

Comments

@cadaniel
Copy link

cadaniel commented May 3, 2021

So I really like where this package is going.

Something I'd like to see is to have dependant cache hold multiple values.

I'd like to build a cache of multiple values, and only compute if that value is new.

For example

string getName(int id) {
    switch(id) {
        case 0: 
            return "zero";
       case 1:
            return "one";
      ....
    }
} 

... 
int id = 0;
final factorialCacheFirst = CachedValue.dependent(
    on: () => id,
    compute: () => getName(id),
  ); // computes

final factorialCacheSecond = CachedValue.dependent(
    on: () => id,
    compute: () => getName(id),
  ); // returns cached value

id = 1;
final factorialCacheThird = CachedValue.dependent(
    on: () => id,
    compute: () => getName(id),
  ); // computes

id = 0;
final factorialCacheSecond = CachedValue.dependent(
    on: () => id,
    compute: () => getName(id),
  ); // returns cached value

id = 1;
final factorialCacheThird = CachedValue.dependent(
    on: () => id,
    compute: () => getName(id),
  ); // computes

The summary is I'd love to cache a function's return value for a variety of inputs.

@renancaraujo
Copy link
Member

Your example is a little bit off but I think I get it.

This generally evolves keeping a cache map of dependency and results.

@spydon
Copy link
Member

spydon commented Jul 15, 2024

The riverpod family provider is really handy to use for that use-case, until we implement your suggestion here (might not happen).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants