cached_value
cached_value copied to clipboard
[Request] Add large cache option
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.
Your example is a little bit off but I think I get it.
This generally evolves keeping a cache map of dependency and results.
The riverpod family provider is really handy to use for that use-case, until we implement your suggestion here (might not happen).