How to cache data for a specific time on riverpod 2.6.1? #3811
Closed
lunxinfeng
started this conversation in
General
Replies: 3 comments 2 replies
-
also can do it like this: Future<T> cacheFor<T>(Duration duration, Future<T> Function() fun) async {
final link = keepAlive();
final timer = Timer(duration, link.close);
try {
return await fun.call();
} catch (e) {
timer.cancel();
return Future.error(e);
}
} But it doesn't look elegant at all. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
this is official advice:
but it will also cache when error, so do some change:
but it cannot cache when only
ref.read
(no watch), so do some change like this:but when riverpod update to 2.6.1,
ref.listenSelf
is deprecated, here is no Notifier too.How do I achieve the above functionality, cache data for a specified time, no cache when error, when only
ref.read
?Hope to answer, thks
Beta Was this translation helpful? Give feedback.
All reactions