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

套件詳情v6.1.1+1

flutter_persistent_queue

適用於 Flutter 的簡單基於檔案的非揮發性持久佇列實作。非常適合在應用程式執行之間必須持續存在的裝置內順序緩衝區。

近 30 天下載
121
喜歡數
10
Pub 分數
40

安裝套件

flutter pub add flutter_persistent_queue

套件介紹

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

一個簡單的基於檔案的持久化佇列,適用於 Flutter,可將資料非易失性地儲存在裝置上。它確保資料完整性與跨應用重啟的持久性,非常適合用來維護任務佇列或記錄等順序緩衝區。以 Dart 編寫,使用本機檔案儲存來可靠地保留項目,即使應用關閉或裝置重新開機也能保持資料。此套件輕量且設計簡潔,便於整合到需要可靠離線資料處理功能的應用中。

適用情境

  • 離線任務排隊
  • 持久化日誌
  • 同步前的資料緩衝
  • 應用重啟容錯
  • 本地狀態持久化
  • 後台操作暫存

主要特色

  • 基於檔案的儲存
  • 非易失性持久化
  • 簡單 API
  • 跨應用重啟耐用性
  • 順序先進先出行為
  • 輕量級實作

適合對象

  • 需要離線資料保留的應用程式
  • 任務管理系統
  • 日誌框架
  • 背景處理工作流程
  • 簡單的狀態組件
  • 低複雜度佇列需求

使用建議

  • 僅限檔案系統儲存
  • 無內建加密
  • 不適合大型資料集
  • 可能需要手動清理
  • 效能取決於磁碟I/O
  • 無雲端同步

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

persistent_queue

Simple file-based non-volatile queue library for flutter.

Typical use-case scenario is for small to medium sized in-device buffers storing persistent yet temporary mission-critical data, until it can be efficiently and safely consumed / delivered permanently - such as for custom analytics and specialized logging applications.

Installation

Add dependency to pubspec.yaml:

dependencies:
  ...
  flutter_persistent_queue: ^6.2.0

Run in your terminal:

flutter packages get

Example

import 'package:flutter_persistent_queue/flutter_persistent_queue.dart';

// instantiate a new queue `pq`, with auto-flush set at 10 items
final pq = PersistentQueue('pq', flushAt: 10, onFlush: (list) async {
  print('auto-flush\n$list');
});

// push 25 Map<<String, dynamic>> items (await is optional)
for (int i = 0; i < 25; ++i) {
  pq.push(<String, dynamic>{'i': i});
}

// trigger a final manual flush for the remaining items
pq.flush((list) async => print('manual-flush\n$list'));

// check if all items have been flushed
assert(await pq.futureLength == 0);

// deallocate resources, if needed
await pq.destroy();

Testing

For integration / performance tests:

git clone https://github.com/oakromulo/flutter_persistent_queue.git
cd ~/flutter_persistent_queue/test
flutter drive --target=test_driver/app.dart

Building documentation files

rm -rf doc
dartdoc --exclude 'dart:async,dart:collection,dart:convert,dart:core,dart:developer,dart:io,dart:isolate,dart:math,dart:typed_data,dart:ui'

How it works

Each JSON-encodable item when enqueued goes to its own indexed key in a single non-volatile file (one file per uniquely named queue) to an unspecified location on the permanent storage of a flutter-compatible device.

This particular design choice limits potential use cases requiring very long queues but otherwise provides good performance within a limited resource footprint, as it doesn't require serializing and deserializing contiguous or chunked dart:collections to the filesystem.

Every push() call triggers an asynchronous and isolated write to the permanent storage. If the caller awaits until its completion, it is notified via Completers and afterwards there's no possibility of data loss from the application perspective.

After user-defined flush() operations (either manual or auto-triggered) the queue is fully emptied if and only if the user-defined onFlush does not throw any errors.

All PersistentQueue methods are consumed sequentially (according to the strict chronological order of its calls) one at a time on a dedicated producer / consumer event loop.

Performance of persisted queues on standard simulated devices must be of at least 500 writes/second. This constraint is verified on integration tests.

All filesystem and JSON operations are abstracted by the minimalistic flutter_localstorage library.

License

MIT

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。