public IEnumerable <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query) { if (query == null) { throw new ArgumentNullException("query"); } if (Interlocked.CompareExchange(ref syncQuotaRows, 1, 0) == 0) { try { var rows = cache.Get(KEY_QUOTA_ROWS) as Dictionary <string, List <TenantQuotaRow> >; if (rows == null || interval.Expired) { var date = rows != null ? interval.StartTime : DateTime.MinValue; interval.Start(CacheExpiration); var changes = service.FindTenantQuotaRows(new TenantQuotaRowQuery(Tenant.DEFAULT_TENANT).WithLastModified(date)) .GroupBy(r => r.Tenant.ToString()) .ToDictionary(g => g.Key, g => g.ToList()); // merge changes from db to cache if (rows == null) { rows = changes; } else { foreach (var p in changes) { if (rows.ContainsKey(p.Key)) { var cachedRows = rows[p.Key]; foreach (var r in p.Value) { cachedRows.RemoveAll(c => c.Path == r.Path); cachedRows.Add(r); } } else { rows[p.Key] = p.Value; } } } cache.Insert(KEY_QUOTA_ROWS, rows, DateTime.UtcNow.Add(CacheExpiration)); } } finally { syncQuotaRows = 0; } } var quotaRows = cache.Get(KEY_QUOTA_ROWS) as IDictionary <string, List <TenantQuotaRow> >; if (quotaRows == null) { return(new TenantQuotaRow[0]); } lock (quotaRows) { var list = quotaRows.ContainsKey(query.Tenant.ToString()) ? quotaRows[query.Tenant.ToString()] : new List <TenantQuotaRow>(); if (query != null && !string.IsNullOrEmpty(query.Path)) { return(list.Where(r => query.Path == r.Path)); } return(list.ToList()); } }
public List <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query) { return(quotaService.FindTenantQuotaRows(query).ToList()); }
public List <TenantQuotaRow> FindTenantQuotaRows(int tenantId) { return(quotaService.FindTenantQuotaRows(tenantId).ToList()); }