resource_cache 0.87.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

resource_cache #

resource_cache is a Dart library for retrieving, caching and managing remote HTTP resources.

Usage #

import "dart:io";
import "package:resource_cache/resource_cache.dart";

void main() async {

  //Directory that the cache directory will be created within.
  Directory d = Directory.systemTemp;

  //create the cache, passing in the root directory.
  var cache = ResourceCache(d);

  //Url to retrieve
  var url = "http://mikechambers.com/blog/images/posts/twitchlivefirefox/screenshot.png";

  //This returns a file referencing a cached local copy of the remote resource.
  File f  = await cache.retrieve(url);

  print(f.path);
}

Installation #

Add the following to your pubspec.yaml file:

resource_cache:

and then run

pub get

#changelog

0.87.0 #

  • If image cannot be retrieved, we return null

0.86.0 #

  • retrieve now returns a File instance pointing to the cached resouce, and not a String.

0.85.2 #

  • Added changelog.
  • Update description to be shorter.
  • Added missing await.

0.85.0 #

Initial Release

example/main.dart

import "dart:io";
import "package:resource_cache/resource_cache.dart";

void main() async {

  //Directory that the cache directory will be created within.
  Directory d = Directory.systemTemp;

  //create the cache, passing in the root directory.
  var cache = ResourceCache(d);

  //Url to retrieve
  var url = "http://mikechambers.com/blog/images/posts/twitchlivefirefox/screenshot.png";

  //This returns a Uri. It will be a file:/ uri if the file was already cached, or
  //succesfully cached.
  //It the original Uri if there was an error, or the file could not be cached.
  File f = await cache.retrieve(url);

  print(f.path);
  exit(0);
}

Use this package as a library

1. Depend on it

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


dependencies:
  resource_cache: ^0.87.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:resource_cache/resource_cache.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/resource_cache.dart. (-1.49 points)

Analysis of lib/resource_cache.dart reported 3 hints:

line 25 col 14: Unnecessary new keyword.

line 30 col 15: Unnecessary new keyword.

line 66 col 29: Unnecessary new keyword.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
crypto ^2.0.6 2.1.4
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
typed_data 1.1.6