public ItemCacheL2 GetLevel2Cache(byte itemType) { ItemCacheL2 result; if (itemCaches.TryGetValue(itemType, out result)) { return(result); } if (!itemCaches.TryGetValue(itemType, out result)) { result = new ItemCacheL2(maxLockMilliseconds); itemCaches.TryAdd(itemType, result); } return(result); }
/// <summary> /// The get level 2 cache. /// </summary> /// <param name = "itemType"> /// The item type. /// </param> /// <returns> /// the level2 cache for the item type /// </returns> private ItemCacheL2 GetLevel2Cache(byte itemType) { ItemCacheL2 result; using (ReadLock.TryEnter(this.readerWriterLock, this.maxLockMilliseconds)) { if (this.itemCaches.TryGetValue(itemType, out result)) { return(result); } } using (WriteLock.TryEnter(this.readerWriterLock, this.maxLockMilliseconds)) { if (false == this.itemCaches.TryGetValue(itemType, out result)) { result = new ItemCacheL2(this.maxLockMilliseconds); this.itemCaches.Add(itemType, result); } return(result); } }
public Dictionary <string, Item> GetItems(byte type) { ItemCacheL2 level2Cache = GetLevel2Cache(type); string[] ids = null; Dictionary <string, Item> result = new Dictionary <string, Item>(); if (level2Cache.TryGetIds(out ids)) { if (ids != null) { for (int i = 0; i < ids.Length; i++) { Item it; if (level2Cache.TryGetItem(ids[i], out it)) { result.Add(ids[i], it); } } } } return(result); }
/// <summary> /// Adds an <see cref = "Item" />. /// </summary> /// <param name = "item"> /// The new item. /// </param> /// <returns> /// true if item added. /// </returns> public bool AddItem(Item item) { ItemCacheL2 level2Cache = this.GetLevel2Cache(item.Type); return(level2Cache.AddItem(item)); }
/// <summary> /// Tries to retrieve an <see cref = "Item" />. /// </summary> /// <param name = "itemType"> /// The item Type. /// </param> /// <param name = "itemId"> /// The item id. /// </param> /// <param name = "item"> /// The found item. /// </param> /// <returns> /// true if item was found. /// </returns> public bool TryGetItem(byte itemType, string itemId, out Item item) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.TryGetItem(itemId, out item)); }
/// <summary> /// Removes an <see cref = "Item" />. /// </summary> /// <param name = "itemType"> /// The item Type. /// </param> /// <param name = "itemId"> /// The item id. /// </param> /// <returns> /// true if item removed. /// </returns> public bool RemoveItem(byte itemType, string itemId) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.RemoveItem(itemId)); }
public int GetCount(byte itemType) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.count); }
public int GetCount(byte itemType, System.Func <Item, bool> predicate) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.Count(predicate)); }
public bool TryGetIds(byte itemType, out string[] ids) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.TryGetIds(out ids)); }
public bool TryGetItem(byte itemType, Vector3 center, float radius, Func <Item, bool> customFilter, out Item item) { ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType); return(level2Cache.TryGetItem(center, radius, customFilter, out item)); }
/// <summary> /// The get level 2 cache. /// </summary> /// <param name = "itemType"> /// The item type. /// </param> /// <returns> /// the level2 cache for the item type /// </returns> private ItemCacheL2 GetLevel2Cache(byte itemType) { ItemCacheL2 result; using (ReadLock.TryEnter(this.readerWriterLock, this.maxLockMilliseconds)) { if (this.itemCaches.TryGetValue(itemType, out result)) { return result; } } using (WriteLock.TryEnter(this.readerWriterLock, this.maxLockMilliseconds)) { if (false == this.itemCaches.TryGetValue(itemType, out result)) { result = new ItemCacheL2(this.maxLockMilliseconds); this.itemCaches.Add(itemType, result); } return result; } }