jaguar_cache 2.1.2

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

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

Alternatively, your editor might support pub get or flutter 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
2.1.2 Aug 8, 2018 Go to the documentation of jaguar_cache 2.1.2 Download jaguar_cache 2.1.2 archive
2.1.1 Aug 8, 2018 Go to the documentation of jaguar_cache 2.1.1 Download jaguar_cache 2.1.1 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
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

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.

Dependencies

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