jaguar_cache_redis 0.1.1

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

jaguar_cache_redis

Cache implementation based on Redis

Example

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

main() async {
  final cache = new RedisCache(new Duration(minutes: 1), new JsonRepo());

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

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

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

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

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

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

  await cache.remove('one');

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

Operations

Upsert

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

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

Read

Get the content associated with the given key

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

Read many

Get the content associated multiple keys at once.

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

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

Replace

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

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

Remove

Deletes the given key from the cache

await cache.remove('one');

Changelog

0.1.1

  • Negative or null expiry means no expiration

0.0.1

  • Initial version, created by Stagehand

example/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_redis/jaguar_cache_redis.dart';

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

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

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

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

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

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

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

  await cache.remove('one');

  try {
    await 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_redis: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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_redis/jaguar_cache_redis.dart';
  
Version Uploaded Documentation Archive
0.1.1 Jul 23, 2017 Go to the documentation of jaguar_cache_redis 0.1.1 Download jaguar_cache_redis 0.1.1 archive
0.1.0 Jul 22, 2017 Go to the documentation of jaguar_cache_redis 0.1.0 Download jaguar_cache_redis 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0