call method

T call(
  1. A arg, {
  2. bool overrideCache = false,
})

Invokes the calculateValue with the given arg, then stores and returns the resolved value.

The provided arg represent the dependencies that bind the cached value, so if it has already been resolved, the value is immediately returned from the cache.

Set overrideCache to true to ignore the cached value and re-call the calculateValue.

Implementation

T call(A arg, {bool overrideCache = false}) {
  _interceptor?.onInit(this, arg);

  if (!overrideCache && _cache.containsKey(arg.hashCode)) {
    final valueCached = _cache[arg.hashCode] as T;

    _interceptor?.onValue(this, arg, valueCached, true);
    _interceptor?.onFinish(this, arg);

    return valueCached;
  }

  try {
    final valueCalculated = _computeValue(arg);

    _cache[arg.hashCode] = valueCalculated;

    _interceptor?.onValue(this, arg, valueCalculated, false);
    _interceptor?.onFinish(this, arg);

    return valueCalculated;
  } catch (error) {
    _interceptor?.onError(this, arg, error);
    _interceptor?.onFinish(this, arg);

    rethrow;
  }
}