flutter_cache 0.0.4 copy "flutter_cache: ^0.0.4" to clipboard
flutter_cache: ^0.0.4 copied to clipboard

outdated

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.

flutter_cache #

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.

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

// 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.0.1

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';

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.

await Cache.remember('key', () {
  return 'test'; // or logic fetching data from api;
});

// or 

await Cache.remember('key', () => 'test');

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.
22
likes
0
pub points
84%
popularity

Publisher

unverified uploader

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.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on flutter_cache