Line data Source code
1 : /// Used for caching calculated values, the cache is determined to be valid by 2 : /// comparing a list of values that can be of any type and is compared to the 3 : /// values that was last used when the cache was updated. 4 : class ValueCache<T> { 5 : T? value; 6 : 7 : List<dynamic> _lastValidCacheValues = <dynamic>[]; 8 : 9 29 : ValueCache(); 10 : 11 9 : bool isCacheValid<F>(List<F> validCacheValues) { 12 9 : if (value == null) { 13 : return false; 14 : } 15 36 : for (var i = 0; i < _lastValidCacheValues.length; ++i) { 16 36 : if (_lastValidCacheValues[i] != validCacheValues[i]) { 17 : return false; 18 : } 19 : } 20 : return true; 21 : } 22 : 23 9 : T updateCache<F>(T value, List<F> validCacheValues) { 24 9 : this.value = value; 25 9 : _lastValidCacheValues = validCacheValues; 26 : return value; 27 : } 28 : }