Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeshuaro/firestore_cache
A Flutter plugin for fetching Firestore documents with read from cache first then server.
https://github.com/zeshuaro/firestore_cache
dart firebase-firestore flutter flutter-package flutter-plugin
Last synced: 4 months ago
JSON representation
A Flutter plugin for fetching Firestore documents with read from cache first then server.
- Host: GitHub
- URL: https://github.com/zeshuaro/firestore_cache
- Owner: zeshuaro
- License: mit
- Created: 2020-05-03T01:55:25.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T15:26:26.000Z (4 months ago)
- Last Synced: 2024-10-20T17:31:12.635Z (4 months ago)
- Topics: dart, firebase-firestore, flutter, flutter-package, flutter-plugin
- Language: Dart
- Homepage: https://pub.dev/packages/firestore_cache
- Size: 1.35 MB
- Stars: 33
- Watchers: 3
- Forks: 12
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Firestore Cache
[](https://pub.dartlang.org/packages/firestore_cache)
[](https://pub.dev/documentation/firestore_cache/latest/)
[](https://github.com/zeshuaro/firestore_cache/blob/master/LICENSE)
[](https://github.com/zeshuaro/firestore_cache/actions/workflows/github-actions.yml)
[](https://codecov.io/gh/zeshuaro/firestore_cache)
[](https://app.codacy.com/gh/zeshuaro/firestore_cache/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://pub.dev/packages/flutter_lints)[](https://github.com/sponsors/zeshuaro)
[](https://www.buymeacoffee.com/zeshuaro)
[](https://ko-fi.com/zeshuaro)
[](https://liberapay.com/zeshuaro/)
[](https://patreon.com/zeshuaro)
[](https://paypal.me/JoshuaTang)A Flutter plugin for fetching Firestore documents with read from cache first then server.
This plugin is mainly designed for applications using the `DocumentReference.get()` and `Query.get()` methods in the `cloud_firestore` plugin, and is implemented with read from cache first then server.
## Getting Started
Add this to your package's `pubspec.yaml` file:
```yaml
dependencies:
firestore_cache: ^2.14.9
```### Usage
Before using the plugin, you will need to create a document on Firestore and create a timestamp field in that document. See the screenshot below for an example:

__⚠️ PLEASE NOTE__ This plugin does not compare the documents in the cache and the ones in the server to determine if it should fetch data from the server. Instead, it relies on the timestamp field in the document to make that decision. And so your application should implement the logic to update this field if you want to read new data from the server instead of reading it from the cache.
You should also create different timestamp fields for different collections or documents that you are fetching.
```dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_cache/firestore_cache.dart';// This should be the path of the document containing the timestampe field
// that you created
final cacheDocRef = Firestore.instance.doc('status/status');// This should be the timestamp field in that document
final cacheField = 'updatedAt';final query = Firestore.instance.collection('posts');
final snapshot = await FirestoreCache.getDocuments(
query: query,
cacheDocRef: cacheDocRef,
firestoreCacheField: cacheField,
);
```