public async Task <IEnumerable <TopSellers> > GetOrCreate( bool withGarden, int take = 10) { string cacheKey = GetCacheKey(withGarden, take); if (_distributedCache.ContainsKey(cacheKey)) { return(JsonSerializer.Deserialize <IEnumerable <TopSellers> >(_distributedCache.Get(cacheKey))); } using (var cnn = SimpleDbConnection()) { cnn.Open(); IEnumerable <TopSellers> topSellers = await cnn.QueryAsync <TopSellers>( $@"SELECT SellerName, COUNT(1) as AdsCount FROM HouseOffer GROUP BY SellerId, SellerName ORDER BY adsCount DESC LIMIT 0, {take}"); await _distributedCache.SetStringAsync(cacheKey, JsonSerializer.Serialize(topSellers), _cacheOptions); return(topSellers); } }