搜尋套件、儲存庫與 APP 分類

套件詳情v2.21.7

firestore_cache

一個用於從快取中優先讀取,然後從伺服器獲取 Firestore 文件的 Flutter 插件

AndroidiOSWebmacOSWindows
近 30 天下載
3340
喜歡數
107
Pub 分數
160

安裝套件

flutter pub add firestore_cache

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

firestore_cache 是一個 Flutter 套件,可實現從快取優先讀取 Firestore 文件的策略,確保快速的本機回應,同時可選擇性地與伺服器同步。它優先使用快取資料以實現即時顯示,並異步從伺服器更新快取,從而提升應用程式效能與使用者體驗,即使在網路延遲或離線情況下亦然。此套件支援所有主要平台,包括 Android、iOS、Web、macOS 與 Windows,非常適合需要即時資料存取且具備備援可靠性的應用程式。

適用情境

  • 離線優先的資料檢索
  • 快速的初始UI渲染
  • 與 Firestore 的背景同步
  • 改進的應用回應速度
  • 無縫網絡恢復

主要特色

  • 快取優先文件取得
  • 自動伺服器同步
  • 跨平台支援
  • 簡單 API 結合
  • 即時資料一致性

適合對象

  • 需要快速本地資料存取的應用程式
  • 開發人員實現離線功能
  • 使用 Firebase Firestore 的項目
  • 需要即時反饋的UI
  • 網路連接不穩定的應用程式

使用建議

  • 最初可能提供過時的資料
  • 需要仔細處理快取無效化
  • 不適用於即時關鍵更新
  • 限制為 Firestore 文件讀取
  • 網路使用量取決於同步頻率

原始 README

以下為關聯原始碼儲存庫的 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,
);

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。