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

stock.get() waits until query resolves #50

Open
chimon2000 opened this issue Nov 24, 2024 · 0 comments
Open

stock.get() waits until query resolves #50

chimon2000 opened this issue Nov 24, 2024 · 0 comments

Comments

@chimon2000
Copy link

Describe the bug
When using stock.get() the Future resolves after the API query, rather than resolving from the cache, querying, and then updating the cache.

Expected behavior
On refresh, return data for [key] if it is cached otherwise will return fresh/network data (updating your cache).

Screenshots
The fetcher being used to demonstrate the query:

  late final fetcher = Fetcher.ofFuture<String, List<PostNetworkModel>>(
      (_) => Future.delayed(const Duration(seconds: 2)).then(
            (_) => _dataSource.fetchPosts(),
          ));

//...

  Future<List<PostNetworkModel>> getItems() async {
    return _posts.get('posts');
  }

The method testing the request (using a Cubit):

  Future<void> refresh() async {
    debugPrint('refresh started ${DateTime.now()}');

    final items = await _postRepository.getItems();

    debugPrint('refresh ended ${DateTime.now()}');

    emit(StockResponse.data(ResponseOrigin.sourceOfTruth, items));
  }

And the output:

refresh started 2024-11-24 00:20:03.296
refresh ended 2024-11-24 00:20:05.328

Package info:

  • Version: 1.1.2

Additional context
I expect that regardless of whether the cache exists, the query should be executed to refresh the cache.

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

1 participant