public static void RemovePollingForCache(MetaData metaData) { lock (lockObject) { var metaData2 = metaDataList.FirstOrDefault(mdl => mdl.ConnectionString == metaData.ConnectionString && mdl.SchemaName == metaData.SchemaName); if (metaData2 != null) { metaDataList.Remove(metaData2); } } }
public static MetaData GetMetaData(string connectionString, string schemaName) { lock (lockObject) { var metaData = metaDataList.FirstOrDefault(mdl => mdl.ConnectionString == connectionString && mdl.SchemaName == schemaName); if (metaData == null) { metaData = new MetaData(connectionString, schemaName); LoadCacheData(metaData); metaDataList.Add(metaData); } return metaData; } }
private static void LoadCacheData(MetaData metaData) { try { using (var conn = new SqlConnection(metaData.ConnectionString)) { conn.Open(); var comm = new SqlCommand($"select * from [{metaData.SchemaName}].Meta where Pk=@Pk;", conn); comm.Parameters.AddWithValue("Pk", 1); using (var reader = comm.ExecuteReader()) { if (reader.Read()) { metaData.DefaultTimeToLive = TimeSpan.FromSeconds((long)reader["DefaultTTLinSeconds"]); metaData.CacheIsEnabled = (bool) reader["CacheIsEnabled"]; metaData.IsDebugSchema = (bool) reader["IsDebugSchema"]; metaData.LastRunDeleteExpiredCache = (DateTime) reader["LastRunDeleteExpiredCache"]; metaData.MaxRowCountCounterCache = (long) reader["MaxRowCountCounterCache"]; metaData.MaxRowCountBinaryCache = (long)reader["MaxRowCountBinaryCache"]; metaData.MaxRowCountTextCache = (long)reader["MaxRowCountTextCache"]; metaData.MaxPayloadSizeForTextCache = (long) reader["MaxPayloadSizeForTextCache"]; metaData.MaxPayloadSizeForBinaryCache = (long)reader["MaxPayloadSizeForBinaryCache"]; } else { throw new ApplicationException("Could not find configuration in Meta table."); } } } } catch (Exception ex) { //TODO: is there's a problem reading the meta table, we should probably mark the cache as disabled. logger.ErrorFormat("Error while loading MetaData for cache {0}. {1}", metaData.SchemaName, ex); throw; } }