flutter_cs_cache 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 79

flutter_cs_cache

Flutter package to provide simple and extendible cache feature to be used in flutter applications.

Getting Started

Import CsCache as


Once imported make sure you have created CsCache instance ahead of time, before using getKey or setKey functions

### To set a key value
csCache.setKey(key: keyName, value: valueString, expireOn: expiryTimeInMillisecondsSinceEpoch);

### To get a key value
csCache.getKey(key: keyName);

### To remove a key value
csCache.removeKey(key: keyName);

### To purge all keys which might have been expired
csCache.purgeCache();

### To clear all cache entrie (expired and non-expired)
csCache.clearCache();


## example code

class _MyHomePageState extends State<MyHomePage> { String cacheMessage = ""; final CsCache cache = new CsCache(); final String _cacheKey = "1111";

void _checkCache() { String cacheEntry = cache.getKey(key: _cacheKey); if(cacheEntry == null) cache.setKey(key: _cacheKey, value: DateTime.now().toString(), expireOn: DateTime.now().add(new Duration(seconds: 300)).millisecondsSinceEpoch); setState(() { cacheMessage = cacheEntry ?? "Cache entry not found"; }); }

void _removeCacheEntry(){ cache.removeKey(key: _cacheKey); _checkCache(); }

@override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text(widget.title), ), body: new Center( child: new Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ new Text( 'Cache has following value:', style: Theme.of(context).textTheme.title, ), new Text( '$cacheMessage', style: Theme.of(context).textTheme.body1, ),

        SizedBox(height: 50.0,),
        RaisedButton(
          child: Text("Remove Cache Entry"),
          onPressed: _removeCacheEntry,
          )
      ],
    ),
  ),
  floatingActionButton: new FloatingActionButton(
    onPressed: _checkCache,
    tooltip: 'Add cache entry',
    child: new Icon(Icons.add),
  ), // This trailing comma makes auto-formatting nicer for build methods.
);

} }


1.0.0 - Updated release version

  • Added helpful info in readme file

0.0.1 - Initial Release

  • Basic cache features included such as set/get/remove/purge/clear cache

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter_cs_cache/flutter_cs_cache.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Cache Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String cacheMessage = "";
  final CsCache cache = new CsCache();
  final String _cacheKey = "1111";

  void _checkCache() {
    String cacheEntry = cache.getKey(key: _cacheKey);
    if(cacheEntry == null) cache.setKey(key: _cacheKey, value: DateTime.now().toString(), expireOn: DateTime.now().add(new Duration(seconds: 300)).millisecondsSinceEpoch);
    setState(() {
      cacheMessage = cacheEntry ?? "Cache entry not found";
    });
  }

  void _removeCacheEntry(){
    cache.removeKey(key: _cacheKey);
    _checkCache();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'Cache has following value:',
              style: Theme.of(context).textTheme.title,
            ),
            new Text(
              '$cacheMessage',
              style: Theme.of(context).textTheme.body1,
            ),

            SizedBox(height: 50.0,),
            RaisedButton(
              child: Text("Remove Cache Entry"),
              onPressed: _removeCacheEntry,
              )
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _checkCache,
        tooltip: 'Add cache entry',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_cs_cache: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_cs_cache/flutter_cs_cache.dart';
  
Version Uploaded Documentation Archive
1.0.0 Aug 25, 2018 Go to the documentation of flutter_cs_cache 1.0.0 Download flutter_cs_cache 1.0.0 archive
0.0.2 Aug 13, 2018 Go to the documentation of flutter_cs_cache 0.0.2 Download flutter_cs_cache 0.0.2 archive
0.0.1 Aug 13, 2018 Go to the documentation of flutter_cs_cache 0.0.1 Download flutter_cs_cache 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.30.0 <3.0.0
flutter 0.0.0
shared_preferences ^0.4.2 0.4.3
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test