Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.1.0

flutter_cache

Um pacote de cache simples para o flutter. Este pacote é um invólucro para preferências compartilhadas e torna o trabalho com preferências compartilhadas mais fácil.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
1,9 mil
Curtidas
22
Pontos Pub
120

Instalar pacote

flutter pub add flutter_cache

Visão geral do pacote

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

flutter_cache é um pacote leve que simplifica o uso de preferências compartilhadas em aplicativos Flutter. Atua como um wrapper ao redor das preferências compartilhadas, fornecendo uma API fácil de usar para armazenar e recuperar dados persistentemente após reinícios do aplicativo. Projetado para simplicidade e eficiência, suporta todas as principais plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux. O pacote abstrai operações comuns de cache, tornando-o ideal para gerenciar pequenas quantidades de dados persistentes, como configurações do usuário, tokens ou respostas em cache.

Casos de uso

  • Armazenando preferências do usuário
  • Armazenando em cache dados de resposta da API
  • Persistência de tokens de login
  • Salvar estado do aplicativo
  • Gerenciando configurações de configuração

Principais recursos

  • API simples
  • wrapper de preferências compartilhadas
  • Suporte multiplataforma
  • Serialização de dados fácil
  • Leve e rápido

Indicado para

  • Desenvolvedores iniciantes do Flutter
  • Aplicativos que precisam de persistência básica
  • Armazenamento de dados em pequena escala
  • Prototipagem rápida
  • Necessidades simples de cache

Considerações

  • Não adequado para grandes conjuntos de dados
  • Limitado ao armazenamento de chave-valor
  • Sem mecanismo embutido de expiração
  • Depende do desempenho de preferências compartilhadas
  • Não suporta consultas complexas

README original

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

flutter_cache

Dependencies Status file size GitHub Issues follows on twitter

A simple cache package for flutter. This package is a wrapper for shared preference and makes working with shared preference easier. Once it has been installed, you can do these things.

import 'package:flutter_cache/flutter_cache.dart' as cache;

// create new cache.
cache.remember('key', 'data'); 
cache.write('key', 'data'); 

// add Cache lifetime on create
cache.remember('key', 'data', 120); 
cache.write('key', 'data', 120); 

// load Cache by key
cache.load('key'); // This will load the cache data.

// return `defaultValue` if key not exists
cache.load('key', 'defaultValue')

// destroy single cache by key
cache.destroy('key');

// destroy all cache
cache.clear();

Getting Started

Installation

First include the package dependency in your project's pubspec.yaml file

dependencies:
  flutter_cache: ^0.1.0

You can install the package via pub get:

flutter pub get

Then you can import it in your dart code like so

import 'package:flutter_cache/flutter_cache.dart' as cache;
What Can this Package Do ?
  1. Cache String, Map, List<String> and List<Map> for forever or for a limited time.
  2. Load the cache you've cached.
  3. Clear All Cache.
  4. Clear Single Cache.
Usage
Cache Fetch Data from API

If data already exist, then it will use the data in the cache. If it's not, It will fetch the data. You can also set Cache lifetime so your app would fetch again everytime the Cache dies.

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter_cache/flutter_cache.dart' as cache;

var employees = await cache.remember('employees', () async {
  var response = await http.get('http://dummy.restapiexample.com/api/v1/employees');
  return jsonDecode(response.body)['data'].cast<Map>();
}, 120); // cache for 2 mins

// or 

// cache for 2 mins
var employees = await cache.remember(
    'servers', 
    () async => jsonDecode( 
        (await http.get( 'http://dummy.restapiexample.com/api/v1/employees' )
    ).body )['data'].cast<Map>()
, 120);
Saved data for limited time

The data will be destroyed when it reached the time you set.

cache.remember('key', 'data', 120); // saved for 2 mins or 120 seconds
cache.write('key', 'data', 120);
Cache multipe datatype

You can cache multiple datatype. Supported datatype for now are String, Map, List<String> and List<Map>. When you use cache.load() to get back the data, it will return the data in the original datatype.

cache.remember('key', { 
  'name' : 'Ashraf Kamarudin',
  'depth2' : {
    'name' : 'depth2',
    'depth3' : {
      'name': 'depth3'
    } 
  }
});

cache.load('key'); // will return data in map datatype.

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote