搜索插件、代码仓与 APP 分类

插件详情v1.2.0

memory_cache

内存缓存是一个简单、快速且全局的内存缓存,具有 CRUD 功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
4920
喜欢数
36
Pub 分数
160

安装插件

flutter pub add memory_cache

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Memory Cache 是一个轻量级、高性能的内存缓存解决方案,适用于 Flutter 应用程序。它提供简单的 CRUD(创建、读取、更新、删除)操作,可在不同平台上临时存储和检索数据。专为速度和简单性设计,它在应用程序内全局运行,非常适合缓存 API 响应、用户偏好或任何需要快速访问的临时数据。该缓存不会在应用重启后持久化,确保其适合临时存储需求。

适合场景

  • 缓存 API 响应
  • 存储用户会话数据
  • 临时状态管理
  • 优化重复的数据获取
  • 减少网络调用
  • 快速本地数据检索

主要特点

  • 简单的 CRUD 操作
  • 全局缓存实例
  • 高性能
  • 跨平台支持
  • 无持久性
  • 与 Flutter 的轻松集成

适合对象

  • 需要快速内存存储的开发人员
  • 频繁数据查询的应用程序
  • 原型设计与测试
  • 轻量级缓存,无依赖
  • 临时数据处理

使用建议

  • 数据在应用重启后丢失
  • 不适用于持久存储
  • 受限于内存容量
  • 无内置过期策略
  • 不适用于大型数据集

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Memory Cache

Memory Cache is simple, fast and global in-memory cache.

Features

  • Create, read, update, delete and invalidate cache.
  • Expirable Cache
  • Creating local MemoryCache instance.

Getting started

Use this package as a Library

Depend On it

Run this command

with Dart:

$ dart pub add memory_cache

with Flutter:

$ flutter pub add memory_cache

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get or flutter pub get):

dependencies:
  memory_cache: ^1.2.0

Usage

Create New Value
MemoryCache.instance.create('myKey', 'myValue');

with Expiry:

MemoryCache.instance.create(
    'myKey',
    'myValue',
    expiry: const Duration(seconds: 5),
  );
Read Value
final myValue = MemoryCache.instance.read<String>('myKey');
Update Value
MemoryCache.instance.update('myKey', 'myUpdatedValue');
Delete Value
MemoryCache.instance.delete('myKey');
Local Instance

MemoryCache can be created locally and same features will be supported

final MemoryCache localCache = MemoryCache();

所属分类

源码仓库

使用此插件的项目