public IComputed?TryGet(ComputedInput key) { var random = Randomize(key.HashCode); OnOperation(random); if (_storage.TryGetValue(key, out var entry)) { var value = entry.Computed; if (value != null) { value.Touch(); return(value); } var handle = entry.Handle; value = (IComputed?)handle.Target; if (value != null) { value.Touch(); _storage.TryUpdate(key, new Entry(value, handle), entry); return(value); } if (_storage.TryRemove(key, entry)) { _gcHandlePool.Release(handle, random); } } return(null); }
public virtual IComputed?TryGet(ComputedInput key) { var random = Randomize(key.HashCode); OnOperation(random); if (_storage.TryGetValue(key, out var handle)) { var value = (IComputed?)handle.Target; if (value != null) { return(value); } if (_storage.TryRemove(key, handle)) { _gcHandlePool.Release(handle, random); } } return(null); }
Task IFunction.InvokeAndStripAsync(ComputedInput input, IComputed?usedBy, ComputeContext?context, CancellationToken cancellationToken) => InvokeAndStripAsync((TIn)input, usedBy, context, cancellationToken);
async Task <IComputed> IFunction.InvokeAsync(ComputedInput input, IComputed?usedBy, ComputeContext?context, CancellationToken cancellationToken) => await InvokeAsync((TIn)input, usedBy, context, cancellationToken).ConfigureAwait(false);
public override bool Equals(ComputedInput other) => ReferenceEquals(this, other);
protected abstract Task InvokeAndStripAsync( ComputedInput input, IComputed?usedBy, ComputeContext?context, CancellationToken cancellationToken);
// IFunction Task <IComputed> IFunction.InvokeAsync( ComputedInput input, IComputed?usedBy, ComputeContext?context, CancellationToken cancellationToken) => InvokeAsync(input, usedBy, context, cancellationToken);
protected abstract IComputed?TryGetCached(ComputedInput input);
IComputed?IFunction.TryGetCached(ComputedInput input) => TryGetCached(input);
IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy) => TryGetCached((TIn)input, null);
protected abstract IComputed?TryGetCached(ComputedInput input, IComputed?usedBy);
IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy) => TryGetCached(input, usedBy);