Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev1.0.0+4

cache_manager

Gerenciador de cache para armazenar cache local. O gerenciador de cache é um wrapper para armazenar vários tipos de dados (JSON, String, int, etc.) como cache local no seu aplicativo Flutter.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
4
Curtidas
48
Pontos Pub
140

Instalar pacote

flutter pub add cache_manager

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Cache Manager é um pacote do Flutter projetado para simplificar o armazenamento local de vários tipos de dados, como JSON, strings e inteiros. Ele fornece um wrapper fácil de usar para armazenar e recuperar dados em cache em múltiplas plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux. O pacote gerencia armazenamento de arquivos com eficiência, suporta expiração de cache e se integra perfeitamente em aplicativos Flutter para melhorar o desempenho reduzindo solicitações de rede redundantes. É ideal para gerenciar dados temporários ou frequentemente acessados.

Casos de uso

  • Armazenando em cache respostas da API
  • Armazenando preferências do usuário localmente
  • Persistência de imagens e arquivos de mídia
  • Reduzindo a carga da rede em solicitações repetidas
  • Gerenciando o acesso a dados offline

Principais recursos

  • Suporta vários tipos de dados
  • Compatibilidade multiplataforma
  • Expiração automática do cache
  • API simples para operações de leitura/gravação
  • Integração de sistema de arquivos embutido

Indicado para

  • Aplicativos com chamadas de rede frequentes
  • Aplicações com foco em offline
  • Aplicativos com alto uso de mídia
  • Projetos Flutter intensivos em dados
  • Desenvolvedores procurando cache leve

Considerações

  • Requer limpeza manual do cache para grandes conjuntos de dados
  • Políticas avançadas de cache limitadas
  • Nenhuma criptografia embutida para dados sensíveis
  • Depende das permissões do sistema de arquivos em algumas plataformas
  • Não otimizado para atualizações muito frequentes do cache

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

⚡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.

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.