Dart Documentationangular.coreUnboundedCache<K, V>

UnboundedCache<K, V> class

An unbounded cache.

class UnboundedCache<K, V> implements Cache<K, V> {
 Map<K, V> _entries = <K, V>{};
 int _hits = 0;
 int _misses = 0;

 V get(K key) {
   V value = _entries[key];
   if (value != null || _entries.containsKey(key)) {
     ++_hits;
   } else {
     ++_misses;
   }
   return value;
 }
 V put(K key, V value) => _entries[key] = value;
 V remove(K key) => _entries.remove(key);
 void removeAll() => _entries.clear();
 int get capacity => 0;
 int get size => _entries.length;
 CacheStats stats() => new CacheStats(capacity, size, _hits, _misses);
 // Debugging helper.
 String toString() => "[$runtimeType: size=${_entries.length}, items=$_entries]";
}

Implements

Cache<K, V>

Properties

final int capacity #

int get capacity => 0;

final int size #

int get size => _entries.length;

Methods

V get(K key) #

Returns the value for key from the cache. If key is not in the cache, returns null.

docs inherited from Cache<K, V>
V get(K key) {
 V value = _entries[key];
 if (value != null || _entries.containsKey(key)) {
   ++_hits;
 } else {
   ++_misses;
 }
 return value;
}

V put(K key, V value) #

Inserts/Updates the key in the cache with value and returns the value.

docs inherited from Cache<K, V>
V put(K key, V value) => _entries[key] = value;

V remove(K key) #

Removes key from the cache. If key isn't present in the cache, does nothing.

docs inherited from Cache<K, V>
V remove(K key) => _entries.remove(key);

void removeAll() #

Removes all entries from the cache.

docs inherited from Cache<K, V>
void removeAll() => _entries.clear();

CacheStats stats() #

CacheStats stats() => new CacheStats(capacity, size, _hits, _misses);

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString() => "[$runtimeType: size=${_entries.length}, items=$_entries]";