neat_cache 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Neat Cache #

Abstractions around in-memory caches stores such as redis, with timeouts and automatic reconnects.

Disclaimer: This is not an officially supported Google product.

Example #

import 'dart:async' show Future;
import 'dart:convert' show utf8;
import 'package:neat_cache/neat_cache.dart';

Future<void> main() async {
  final cacheProvider = Cache.redisCacheProvider('redis://localhost:6379');
  final cache = Cache(cacheProvider);

  /// Create a sub-cache using a prefix, and apply a codec to store utf8
  final userCache = cache.withPrefix('users').withCodec(utf8);

  /// Get data form cache
  String userinfo = await userCache['peter-pan'].get();
  print(userinfo);

  /// Put data into cache
  await userCache['winnie'].set('Like honey');

  await cacheProvider.close();
}

Development #

To test the redis CacheProvider a redis instance must be running on localhost:6379, this can be setup with:

  • docker run --rm -p 127.0.0.1:6379:6379 redis

v1.0.1 #

  • Avoid unnecessary purging when calling set with a create function that returns null.

v1.0.0 #

  • Initial release.

example/main.dart

// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:async' show Future;
import 'dart:convert' show utf8;
import 'package:neat_cache/neat_cache.dart';

Future<void> main() async {
  final cacheProvider = Cache.redisCacheProvider('redis://localhost:6379');
  final cache = Cache(cacheProvider);

  /// Create a sub-cache using a prefix, and apply a codec to store utf8
  final userCache = cache.withPrefix('users').withCodec(utf8);

  /// Get data form cache
  String userinfo = await userCache['peter-pan'].get();
  print(userinfo);

  /// Put data into cache
  await userCache['winnie'].set('Like honey');

  await cacheProvider.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  neat_cache: ^1.0.1

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:neat_cache/neat_cache.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
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]
75
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:neat_cache/neat_cache.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
convert ^2.1.1 2.1.1
dartis ^0.3.0 0.3.0
logging ^0.11.3 0.11.3+2
retry ^3.0.0 3.0.0+1
Transitive dependencies
charcode 1.1.2
typed_data 1.1.6
Dev dependencies
pedantic ^1.4.0
test ^1.5.1