weak_cache 1.0.0 copy "weak_cache: ^1.0.0" to clipboard
weak_cache: ^1.0.0 copied to clipboard

Weak cache that uses weak references for holding values.

Weak cache that uses weak references for holding values.

This package is useful in cases when you want to hold an object in cache while it's in usage and accessible and remove it when it's no longer needed.

For example you can hold description object in cache while traversing deep into nested views and it eventually will be removed when you leave all related pages.

Features #

  • Uses WeakReference for storing values.
  • Implements full Map<K, V> interface.

Usage #

Just create cache, add some values, and they'll be removed when all other strong references to they are lost.

// ID - Object cache
final cache = WeakCache<int, Object>();

Object? obj = Object();
cache[0] = obj;
// ...
obj = null;
// ...
// After garbage collection cache[0] will be removed.
cache[0] == null;

See example for detailed test case.

2
likes
140
pub points
5%
popularity

Publisher

unverified uploader

Weak cache that uses weak references for holding values.

Repository (GitHub)
View/report issues

Documentation

API reference

License

ISC (LICENSE)

More

Packages that depend on weak_cache