Example #1
0
        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);
        }
Example #2
0
        /// <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);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        /// <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));
        }
Example #5
0
        /// <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));
        }
Example #6
0
        /// <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));
        }
Example #7
0
        public int GetCount(byte itemType)
        {
            ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType);

            return(level2Cache.count);
        }
Example #8
0
        public int GetCount(byte itemType, System.Func <Item, bool> predicate)
        {
            ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType);

            return(level2Cache.Count(predicate));
        }
Example #9
0
        public bool TryGetIds(byte itemType, out string[] ids)
        {
            ItemCacheL2 level2Cache = this.GetLevel2Cache(itemType);

            return(level2Cache.TryGetIds(out ids));
        }
Example #10
0
        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));
        }
Example #11
0
        /// <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;
            }
        }