private Page TryGetNextPageFromCache(long precedingCheckpoint, string subscriptionId, CancellationToken cancellationToken) { if (IsCachingEnabled && cachedTransactionsByPrecedingCheckpoint.TryGet(precedingCheckpoint, out Transaction cachedTransaction)) { var resultPage = new List <Transaction>(maxPageSize) { cachedTransaction }; while (resultPage.Count < maxPageSize) { long lastCheckpoint = cachedTransaction.Checkpoint; if (cachedTransactionsByPrecedingCheckpoint.TryGet(lastCheckpoint, out cachedTransaction)) { resultPage.Add(cachedTransaction); } else { break; } } logDebug(() => $"Cache Hit: (subscription: {subscriptionId}, precedingCheckpoint: {precedingCheckpoint}, page size: {resultPage.Count}, range: {resultPage.First().Checkpoint}-{resultPage.Last().Checkpoint})"); return(new Page(precedingCheckpoint, resultPage)); } logDebug(() => $"Cache Miss: (subscription: {subscriptionId}, precedingCheckpoint: {precedingCheckpoint})."); return(new Page(precedingCheckpoint, new Transaction[0])); }
private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptionId) { Transaction cachedNextTransaction; if ((transactionCacheByPreviousCheckpoint != null) && transactionCacheByPreviousCheckpoint.TryGet(previousCheckpoint, out cachedNextTransaction)) { var resultPage = new List <Transaction>(maxPageSize) { cachedNextTransaction }; while (resultPage.Count < maxPageSize) { long lastCheckpoint = cachedNextTransaction.Checkpoint; if (transactionCacheByPreviousCheckpoint.TryGet(lastCheckpoint, out cachedNextTransaction)) { resultPage.Add(cachedNextTransaction); } else { StartPreloadingNextPage(lastCheckpoint, subscriptionId); break; } } #if LIQUIDPROJECTIONS_DIAGNOSTICS logger(() => $"Subscription {subscriptionId} has found a page of size {resultPage.Count} " + $"from checkpoint {resultPage.First().Checkpoint} " + $"to checkpoint {resultPage.Last().Checkpoint} in the cache."); #endif return(new Page(previousCheckpoint, resultPage)); } #if LIQUIDPROJECTIONS_DIAGNOSTICS logger(() => $"Subscription {subscriptionId} has not found the next transaction in the cache."); #endif return(new Page(previousCheckpoint, new Transaction[0])); }