gg_cache 1.0.6 copy "gg_cache: ^1.0.6" to clipboard
gg_cache: ^1.0.6 copied to clipboard

A simple cache method that helps us to cache results of a function.

example/gg_cache_example.dart

import 'package:gg_cache/gg_cache.dart';

/// A simple class
class Foo {
  const Foo({required this.a, required this.b});
  final int a;
  final int b;
}

/// Create a cache
final cache = Cache<Foo>();

/// Create a method that creates Foos
Foo createFoo(int a, int b) {
  return cache.cache([a, b], () => Foo(a: a, b: b));
}

void main() {
  /// Crete three objects
  final a0 = createFoo(1, 2);
  final a1 = createFoo(1, 2);
  final b2 = createFoo(1, 3);

  /// a0 and a1 are identical because they take the same keys
  assert(identical(a0, a1));

  /// a0 and b2 are not identical because they take different keys
  assert(!identical(a0, b2));
}
0
likes
160
pub points
44%
popularity

Publisher

verified publisherinlavigo.com

A simple cache method that helps us to cache results of a function.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

gg_list

More

Packages that depend on gg_cache