jaguar_cache 2.1.2

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');
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_cache: ^2.1.2

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

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0

Admin