Restored logic to check cache so that the same item is not added repeatedly

Eliminate AddToCache in the factory constructor.  This was causing the same item to be added to the cache repeatedly.
This commit is contained in:
Rich 2012-11-05 22:02:57 +00:00
parent 2c78c091bf
commit 1df947bdf8

View File

@ -39,22 +39,23 @@ namespace VEPROMS.CSLA.Library
private static List<ItemInfo> _CacheList = new List<ItemInfo>(); private static List<ItemInfo> _CacheList = new List<ItemInfo>();
protected static void AddToCache(ItemInfo itemInfo) protected static void AddToCache(ItemInfo itemInfo)
{ {
//if (!_CacheList.Contains(itemInfo)) if (!_CacheList.Contains(itemInfo))
try
{
_CacheList.Add(itemInfo); // In AddToCache _CacheList.Add(itemInfo); // In AddToCache
} //try
catch (Exception ex) //{
{ // _CacheList.Add(itemInfo); // In AddToCache
_MyLog.ErrorFormat("ItemInfo {0}.{1} already exists in the cache", itemInfo.ItemID,itemInfo.MyItemInfoUnique); //}
} //catch (Exception ex)
//{
// _MyLog.ErrorFormat("ItemInfo {0}.{1} already exists in the cache", itemInfo.ItemID, itemInfo.MyItemInfoUnique);
//}
} }
protected static void RemoveFromCache(ItemInfo itemInfo) protected static void RemoveFromCache(ItemInfo itemInfo)
{ {
while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache
} }
private static Dictionary<string, List<ItemInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemInfo>>(); protected static Dictionary<string, List<ItemInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemInfo>>();
private static void ConvertListToDictionary() protected static void ConvertListToDictionary()
{ {
while (_CacheList.Count > 0) // Move ItemInfo(s) from temporary _CacheList to _CacheByPrimaryKey while (_CacheList.Count > 0) // Move ItemInfo(s) from temporary _CacheList to _CacheByPrimaryKey
{ {
@ -428,7 +429,7 @@ namespace VEPROMS.CSLA.Library
{ get { return _MyItemInfoUnique; } } { get { return _MyItemInfoUnique; } }
protected ItemInfo() protected ItemInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); //AddToCache(this);
} }
private bool _Disposed = false; private bool _Disposed = false;
private static int _CountCreated = 0; private static int _CountCreated = 0;
@ -578,7 +579,7 @@ namespace VEPROMS.CSLA.Library
_ItemID = itemID; _ItemID = itemID;
} }
} }
private void ReadData(SafeDataReader dr) protected void ReadData(SafeDataReader dr)
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode());
try try