public async Task <ActionResult> Top() { try { var wait = 5; retry: TopListData data = TopListCache.GetData(); if (data == null) { wait--; if (wait >= 0) { await Task.Delay(2000); // wait up to 5*2 = 10 seconds... goto retry; } return(Content("Busy, please retry in a minute...")); } int indexerHeight = data.Stats.Item1; if (indexerHeight > data.LastBlock.Height) // best blockheight is cached and may thus lag indexer height { indexerHeight = (int)data.LastBlock.Height; } ViewData["BestHeight"] = indexerHeight; ViewData["IndexerLastSeenAgo"] = (DateTime.UtcNow - data.Stats.Item2).TotalMinutes.ToString("0.0"); ViewData["BestBlockHeight"] = data.LastBlock.Height; return(View(data.TopList)); } catch (Exception e) { return(View("Error")); } }
public static void SetData(TopListData data) { lock (lockObj) { _data = data; } }
public async Task <ActionResult> Top() { try { TopListData data; if (TopListCache != null && DateTime.UtcNow - TopListCache.DateTime <= TimeSpan.FromSeconds(120)) { data = TopListCache; } else { data = new TopListData() { DateTime = DateTime.UtcNow, TopList = await _addressService.GetTopList(), Stats = await _addressService.GetStats(), LastBlock = await _blockService.GetLastBlock() }; TopListCache = data; } int indexerHeight = data.Stats.Item1; if (indexerHeight > data.LastBlock.Height) // best blockheight is cached and may thus lag indexer height { indexerHeight = (int)data.LastBlock.Height; } ViewData["BestHeight"] = indexerHeight; ViewData["IndexerLastSeenAgo"] = (DateTime.UtcNow - data.Stats.Item2).TotalMinutes.ToString("0.0"); ViewData["BestBlockHeight"] = data.LastBlock.Height; return(View(data.TopList)); } catch (Exception e) { return(View("Error")); } }