패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.0+4

cache_manager

로컬 캐시를 저장하기 위한 캐시 매니저입니다. 캐시 매니저는 Flutter 앱에서 다양한 데이터 유형(예: JSON, 문자열, 정수 등)을 로컬 캐시로 저장하기 위한 래퍼입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4
좋아요
48
Pub 점수
140

패키지 설치

flutter pub add cache_manager

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

캐시 매니저는 JSON, 문자열, 정수와 같은 다양한 데이터 유형의 로컬 캐싱을 간소화하기 위해 설계된 플러터 패키지입니다. 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 여러 플랫폼에서 캐시된 데이터를 저장하고 검색하기 위한 사용하기 쉬운 래퍼를 제공합니다. 이 패키지는 파일 저장소를 효율적으로 처리하며 캐시 만료를 지원하고, 중복 네트워크 요청을 줄여 플러터 애플리케이션의 성능을 향상시키기 위해 원활하게 통합됩니다. 일시적 또는 자주 접근되는 데이터 관리에 적합합니다.

사용 사례

  • 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.