flutter_cs_cache 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

flutter_cs_cache #

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

Getting Started #

Import CsCache as

import 'package:flutter_cs_cache/flutter_cs_cache.dart';

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 pub get

Alternatively, your editor might support flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
35
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
77
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (shared_preferences).

Package is getting outdated. (-12.88 points)

The package was last published 58 weeks ago.

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 0.5.3+4
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test