dcache 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

Dcache #

Dcache is a simple library to implement application caching in dart inspired by gcache

Feature #

  • Supports expirable Cache, LFU, LRU.
  • Support eviction
  • Automatically load cache if it doesn't exists. (Optional)
  • Async loading of expirate value
  • Callback for evicted items to perform cleanup (Optional)

Example #

Simple use case #

import 'package:dcache/dcache.dart';

void main() {
  Cache c = new SimpleCache(storage: new SimpleStorage(size: 20));

    c.set("key", 42);
    print(c.get("key")); // 42
    print(c.containsKey("unknown_key")); // false
    print(c.get("unknown_key")); // nil
}

Evict items #

import 'package:dcache/dcache.dart';

void main() {
  Cache c = new SimpleCache(storage: new SimpleStorage(size: 20), onEvict: (key, value) {value.dispose();});

    c.set("key", 42);
    print(c.get("key")); // 42
    print(c.containsKey("unknown_key")); // false
    print(c.get("unknown_key")); // nil
}

Loading function #

import 'package:dcache/dcache.dart';

void main() {
  Cache c = new SimpleCache<int, int>(storage: new SimpleStorage(size: 20))
    ..loader = (key, oldValue) => key*10
  ;

    print(c.get(4)); // 40
    print(c.get(5)); // 50
    print(c.containsKey(6)); // false
}

Author #

Kevin PLATEL

0.3.0 #

  • Add OnEvit option to catch eviction and do logic on it (thx to mikes222)

0.2.1 #

  • Improve algorithm time to insertion
  • reduce min version of meta to be compatible with flutter

0.2.0 #

  • Update dependencies
    • meta
  • Use google linters rules based on pedantic package
  • Fix implicit cast
  • Add README.md in examples
  • Fixing linters on setter return type
  • Fix dart sdk to use dart2

example/README.md

EXAMPLE #

Use this package as a library

1. Depend on it

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


dependencies:
  dcache: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:dcache/dcache.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
93
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
91
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/cache.dart. (-2.96 points)

Analysis of lib/src/cache.dart reported 6 hints, including:

line 24 col 23: Unnecessary new keyword.

line 34 col 37: Unnecessary new keyword.

line 40 col 9: Unnecessary new keyword.

line 45 col 22: Unnecessary new keyword.

line 68 col 34: Unnecessary new keyword.

Fix lib/src/cache/lfu_cache.dart. (-1 points)

Analysis of lib/src/cache/lfu_cache.dart reported 2 hints:

line 27 col 34: Unnecessary new keyword.

line 27 col 63: Unnecessary new keyword.

Fix lib/src/cache/lru_cache.dart. (-1 points)

Analysis of lib/src/cache/lru_cache.dart reported 2 hints:

line 27 col 34: Unnecessary new keyword.

line 27 col 63: Unnecessary new keyword.

Fix additional 4 files with analysis or formatting issues. (-2 points)

Additional issues in the following files:

  • lib/src/cache/simple_cache.dart (2 hints)
  • lib/src/cache_entry.dart (1 hint)
  • lib/src/storage/simple_storage.dart (1 hint)
  • lib/dcache.dart (Run dartfmt to format lib/dcache.dart.)

Maintenance suggestions

Package is getting outdated. (-9.32 points)

The package was last published 57 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
meta ^1.1.6 1.2.1
Dev dependencies
pedantic ^1.4.0
test ^1.5.1