jaguar_cache 0.2.1

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

jaguar_cache

Cache layer for Jaguar

Example

import 'dart:async';
import 'package:jaguar_cache/jaguar_cache.dart';
import 'package:jaguar_serializer/serializer.dart';

main() async {
  final repo = new JsonRepo();
  final cache = new InMemoryCache(repo);

  // Upsert
  cache.upsert('one', 1, new Duration(seconds: 5));
  print(cache.read('one'));

  // Replace
  cache.replace('one', 2, new Duration(seconds: 5));
  print(cache.read('one'));

  // Expire
  await new Future.delayed(new Duration(seconds: 5));

  try {
    cache.read('one');
  } catch(e) {
    print('Success! $e');
  }

  cache.upsert('one', 1.0, new Duration(seconds: 5));
  cache.upsert('two', 2.0, new Duration(seconds: 5));

  print(cache.readMany(['one', 'two']));
}

Operations

Upsert

Sets the given key/value in the cache, overwriting any existing value associated with that key.

  cache.upsert('one', 1, new Duration(seconds: 5));
  print(cache.read('one'));

Read

Get the content associated with the given key

  print(cache.read('one'));

Read many

Get the content associated multiple keys at once.

  cache.upsert('one', 1.0, new Duration(seconds: 5));
  cache.upsert('two', 2.0, new Duration(seconds: 5));

  print(cache.readMany(['one', 'two']));

Replace

Set the given key/value in the cache ONLY IF the key already exists.

  cache.replace('one', 2, new Duration(seconds: 5));
  print(cache.read('one'));

Remove

Deletes the given key from the cache

cache.remove('one');

Changelog

0.2.1

  • clear method to wipe the cache

0.2.0

  • Typed Cache

0.1.2

  • Negative or null expiry means, no expiration

0.1.0

  • [InMemoryCache] implementation

example/jaguar_cache_example.dart

// Copyright (c) 2017, teja. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'package:jaguar_cache/jaguar_cache.dart';

main() async {
  final cache = new InMemoryCache(new Duration(minutes: 1));

  // Upsert
  cache.upsert('one', 1, new Duration(seconds: 5));
  print(cache.read('one'));

  // Replace
  cache.replace('one', 2, new Duration(seconds: 5));
  print(cache.read('one'));

  // Expire
  await new Future.delayed(new Duration(seconds: 5));

  try {
    cache.read('one');
  } catch (e) {
    print('Success! $e');
  }

  cache.upsert('one', 1.0, new Duration(seconds: 10));
  cache.upsert('two', 2.0, new Duration(seconds: 10));

  print(cache.readMany(['one', 'two']));

  cache.remove('one');

  try {
    cache.read('one');
  } catch (e) {
    print('Success! $e');
  }
}

1. Depend on it

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


dependencies:
  jaguar_cache: "^0.2.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_cache/jaguar_cache.dart';
        
Version Uploaded Documentation Archive
0.2.1 Oct 11, 2017 Go to the documentation of jaguar_cache 0.2.1 Download jaguar_cache 0.2.1 archive
0.2.0 Oct 11, 2017 Go to the documentation of jaguar_cache 0.2.0 Download jaguar_cache 0.2.0 archive
0.1.2 Jul 23, 2017 Go to the documentation of jaguar_cache 0.1.2 Download jaguar_cache 0.1.2 archive
0.1.1 Jul 21, 2017 Go to the documentation of jaguar_cache 0.1.1 Download jaguar_cache 0.1.1 archive
0.1.0 Jul 21, 2017 Go to the documentation of jaguar_cache 0.1.0 Download jaguar_cache 0.1.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
47 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
73

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jaguar_cache/jaguar_cache.dart.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
Dev dependencies
test ^0.12.0