FLUTTER ECOSYSTEM

zeshuaro/firestore_cache

캐시에서 먼저 읽은 후 서버에서 가져오는 Firestore 문서를 위한 플러터 플러그인입니다.

firestore_cache 프로젝트 이미지
Stars
37
Forks
11
최근 푸시(UTC)
2026. 9. 19.
프로젝트 상태
활성
Joshua Tang GitHub avatar
GITHUB User

Joshua Tang ↗

언어DartRubyPythonSwiftKotlinObjective-C

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 7 개

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

Firestore Cache

pub package docs MIT License GitHub Actions codecov Codacy Badge style: flutter_lints

Github-sponsors BuyMeACoffee Ko-Fi LiberaPay Patreon PayPal

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:

dependencies:
  firestore_cache: ^2.21.2
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:

Firestore Screenshot

⚠️ 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.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firestore_cache/firestore_cache.dart';

// This should be the path of the document containing the timestamp 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,
);