/// <summary> /// Get the details of a blob from a specified id. Returns 'Null' if the /// data isn't available. /// </summary> public Meta Get(string id) { // check the cache var meta = _cache.Get(id); // was the metadata retrieved from the cache? if (meta == null) { // no, get the row var row = Select(Length, SectionCount, SectionLength) .Where(Id).EqualTo(id) .First(); // was the row retrieved? no, return null if (row == null) { return(null); } // return a completed blob specification meta = new Meta(row.A, row.B, row.C); } // return the metadata retrieved or existing in the cache return(_cache.AddOrGet(id, meta)); }
public async Task Intercept_throwsMessageExecutionExceptionFromCache() { await Cache.AddOrGet(Message.GetSha1(), _ => new CachingExceptionResult(new TestMessageExecutionException())); await Interceptor.Awaiting(x => x.Intercept(Fail(new ArgumentException()), Message)) .Should().ThrowAsync <TestMessageExecutionException>(); }
/// <summary> /// Get a blob data row by id and index. /// </summary> public byte[] Get(string id, int index) { var cacheId = new Struct <string, int>(id, index); // get from the cache var data = _cache.Get(cacheId); // was the data retrieved from the cache? if (data == null) { // no, get the row from the table data = Select(Bytes) .Where(Id).EqualTo(id) .Where(SectionIndex).EqualTo(index) .First().A; // were the bytes found? no, return null if (data == null) { return(null); } } // add the retrieved data to the cache return(_cache.AddOrGet(cacheId, data)); }