搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。