public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig, bool conversionOnly = false) { lock (Cache) { ConfigTableCache tableCache; if (!Cache.TryGetValue(type, out tableCache)) { var baseStorageConfig = CreateStorageConfig(type, actualTableName: null, flatConfig: flatConfig); tableCache = new ConfigTableCache(baseStorageConfig); Cache[type] = tableCache; } // If this type is only used for conversion, do not attempt to populate the config from the table if (conversionOnly) { return(tableCache.BaseTypeConfig); } string actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); ItemStorageConfig config; if (!tableCache.Cache.TryGetValue(actualTableName, out config)) { config = CreateStorageConfig(type, actualTableName, flatConfig); tableCache.Cache[actualTableName] = config; } return(config); } }
public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig) { lock (Cache) { ConfigTableCache tableCache; if (!Cache.TryGetValue(type, out tableCache)) { var baseStorageConfig = CreateStorageConfig(type, null); tableCache = new ConfigTableCache(baseStorageConfig); Cache[type] = tableCache; } string actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); ItemStorageConfig config; if (!tableCache.Cache.TryGetValue(actualTableName, out config)) { config = CreateStorageConfig(type, actualTableName); tableCache.Cache[actualTableName] = config; } return(config); } }
public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig, bool conversionOnly = false) { ConfigTableCache tableCache = null; ItemStorageConfig config; string actualTableName = null; try { _readerWriterLockSlim.EnterReadLock(); Cache.TryGetValue(type, out tableCache); if (tableCache != null) { // If this type is only used for conversion, do not attempt to populate the config from the table if (conversionOnly) { return(tableCache.BaseTypeConfig); } actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); if (tableCache.Cache.TryGetValue(actualTableName, out config)) { return(config); } } } finally { if (_readerWriterLockSlim.IsReadLockHeld) { _readerWriterLockSlim.ExitReadLock(); } } try { _readerWriterLockSlim.EnterWriteLock(); if (tableCache == null) { // Check to see if another thread go the write lock before this thread and filled the cache. Cache.TryGetValue(type, out tableCache); if (tableCache == null) { var baseStorageConfig = CreateStorageConfig(type, actualTableName: null); tableCache = new ConfigTableCache(baseStorageConfig); Cache[type] = tableCache; } } // If this type is only used for conversion, do not attempt to populate the config from the table if (conversionOnly) { return(tableCache.BaseTypeConfig); } if (actualTableName == null) { actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); } // Check to see if another thread go the write lock before this thread and filled the cache. if (tableCache.Cache.TryGetValue(actualTableName, out config)) { return(config); } config = CreateStorageConfig(type, actualTableName); tableCache.Cache[actualTableName] = config; return(config); } finally { if (_readerWriterLockSlim.IsWriteLockHeld) { _readerWriterLockSlim.ExitWriteLock(); } } }