パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.0+4

cache_manager

ローカルキャッシュを保存するためのキャッシュマネージャー。キャッシュマネージャーは、Flutterアプリケーション内でさまざまなデータ型(JSON、文字列、intなど)をローカルキャッシュとして保存するためのラッパーです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
4
いいね数
48
Pub ポイント
140

パッケージをインストール

flutter pub add cache_manager

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

キャッシュマネージャーは、JSON、文字列、整数などのさまざまなデータ型のローカルキャッシングを簡素化することを目的としたFlutterパッケージです。Android、iOS、Web、macOS、Windows、Linuxなど、複数のプラットフォームでキャッシュされたデータを保存および取得するための使いやすいラッパーを提供します。このパッケージはファイルストレージを効率的に処理し、キャッシュの有効期限をサポートし、再発生するネットワークリクエストを減らすことでFlutterアプリケーションのパフォーマンスを向上させるためにシームレスに統合されます。一時的または頻繁にアクセスされるデータの管理に最適です。

用途

  • API レスポンスのキャッシュ
  • ユーザーの設定をローカルに保存する
  • 画像およびメディアファイルの永続化
  • 繰り返しリクエスト時のネットワーク負荷の軽減
  • オフラインデータアクセスの管理

主な機能

  • 複数のデータ型をサポートしています
  • クロスプラットフォーム互換性
  • 自動キャッシュの有効期限切れ
  • 読み取り/書き込み操作のためのシンプルな API
  • 組み込みファイルシステム統合

適している対象

  • 頻繁にネットワーク呼び出しを行うアプリ
  • オフライン優先のアプリケーション
  • メディア重視のアプリ
  • データ集約型のFlutterプロジェクト
  • 軽量なキャッシュを求める開発者

注意事項

  • 大規模なデータセットには手動でのキャッシュクリーンアップが必要です
  • 限定された高度なキャッシュポリシー
  • 機密データ用の組み込み暗号化なし
  • 一部のプラットフォームではファイルシステムの権限に依存します
  • 非常に高い周波数のキャッシュ更新には最適化されていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

⚡Cache Manager

A tidy utility to handle cache of your flutter app like a Boss. It provides support for both iOS and Android platforms (offcourse).

🎖Installing

dependencies:
  cache_manager: ^<latest_version>

⚽Awesome Features

🍧Cache Utilities

🌟CacheManagerUtils.conditionalCache({key, valueType, actionIfNull, actionIfNotNull})

  • Conditional builder based on the value of cache. actionIfNull & actionIfNotNull are dynamic arguments used for Navigation through views, Rendering UI, Debugging values etc. The valueType refers to the datatype of cache (StringValue, BoolValue, IntValue, DoubleValue)

🌟CacheManagerUtils.cacheTextBuilder(textStyle, cacheKey})

  • TextBuilder for the cached value. cacheKey is the key used to address the cache. The builder will return 'Invalid cache' if no cache is missing. Use textStyle to style the value of the cache.
👀Read cache

🌟ReadCache.getJson(key) : Get JSON stored as cache.

🌟ReadCache.getString(key) : Get string stored as cache.

🌟ReadCache.getBool(key) : Get boolean stored as cache.

🌟ReadCache.getInt(key) : Get integer stored as cache.

🌟ReadCache.getDouble(key) : Get double stored as cache.

🖊Write cache

🌟WriteCache.setJson(key,value) : Set JSON as cache.

🌟WriteCache.setString(key,value) : Set a string as cache.

🌟WriteCache.setInt(key,value) : Set an integer as cache.

🌟WriteCache.setBool(key,value) : Set a boolean as cache.

🌟WriteCache.setDouble(key,value) : Set a double as cache.

🌟WriteCache.setListString(key,value) : Set a List of string as cache.

❌Delete cache

🌟DeleteCache.deleteKey(key,[takeAction]) : Delete the cache and perform an action when cache is deleted(Optional).

Example : Login flow with caching userID

//Attached function in a login view
Future<String?> login({
    required BuildContext context,
    required String email,
    required String password,
  }) async {
    try {
      var userId = await _authenticationService.login(
          context: context, email: email, password: password);
      await WriteCache.setString(key: "cache", value: userId!);
    } catch (e) {
      print(e); //Do something if error occurs
   }
 }
 
//Splash view
import 'dart:async';
import 'package:cache_manager/cache_manager.dart';
import 'package:flutter/material.dart';

class SplashView extends StatefulWidget {
  @override
  _SplashViewState createState() => _SplashViewState();
}

class _SplashViewState extends State<SplashView> {
  Future initiateCache() async {
    return CacheManagerUtils.conditionalCache(
        key: "cache",
        valueType: ValueType.StringValue,
        actionIfNull: () {
          Navigator.of(context).pushNamed(AppRoutes.LoginRoute);
        },
        actionIfNotNull: () {
          Navigator.of(context).pushNamed(AppRoutes.HomeRoute);
        });
  }

  @override
  void initState() {
    Timer(Duration(seconds: 1), initiateCache);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text("demo app"),
      ),
    );
  }
}

//Home view
import 'package:cache_manager/core/cache_manager_utils.dart';
import 'package:cache_manager/core/delete_cache_service.dart';
import 'package:flutter/material.dart';

class HomeView extends StatefulWidget {
  @override
  _HomeViewState createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: CacheManagerUtils.cacheTextBuilder(
            textStyle: TextStyle(color: Colors.white), cacheKey: "cache"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          DeleteCache.deleteKey(
              "cache", Navigator.of(context).pushNamed(AppRoutes.LoginRoute));
        },
      ),
    );
  }
}
❤Loved the utility? Donate here.
🚀Want to learn more about Flutter? Checkout this out!
💥DM me on Instagram for doubts Follow here

🐛 Bugs/Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github and I'll look into it. Pull request are also welcome.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。