public async Task Set(string key, CancellationToken cancellationToken) { var h = KNodeId <KNodeId256> .Read(new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(key))); var v = await values.GetAsync(h, cancellationToken); await values.SetAsync(h, new KValueInfo(await Request.Body.ReadAllBytesAsync(), v.HasValue ? (v.Value.Version + 1) : 1, DateTime.UtcNow.AddMinutes(60)), cancellationToken); }
/// <summary> /// Gets the value for the key from the hashtable. /// </summary> /// <param name="key"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <KsHashTableValue?> GetAsync(TKey key, CancellationToken cancellationToken = default) { var h = hasher.Hash(key); var v = await values.GetAsync(h, cancellationToken); return(v != null ? new KsHashTableValue(v.Value.Data, v.Value.Version, v.Value.Expiration - DateTime.Now) : (KsHashTableValue?)null); }