public async Task <TValue> AddOrGet(TKey key, Func <TKey, Task <TValue> > addFactory, CancellationToken token) { var keyContent = await KeyConverter.Convert(key, token); var keyRecord = new KeyRecord( id: keyContent.GetSha1(), type: KeyType, content: keyContent); var valueRecord = await backedStorage.AddOrGet( keyRecord, addFactory : async _ => { var value = await addFactory(key); var content = await ValueConverter.Convert(value, token); var audit = new Audit(diagnosticContext.CorrelationId, diagnosticContext.User); return(new ValueRecord(ValueType, content, audit)); }, token); return(await ValueConverter.Convert(valueRecord.Content, token)); }