示例#1
0
        /// <summary>
        /// Contatains or not
        /// </summary>
        /// <param name="item">cachebox item</param>
        /// <returns>true or false</returns>
        public bool Contains(CacheBox <T> item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(_cachedData.Contains(item));
        }
示例#2
0
        /// <summary>
        /// remove item from cache
        /// </summary>
        /// <param name="item">item to be removed</param>
        /// <returns>true or false</returns>
        public bool Remove(CacheBox <T> item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(_cachedData.Remove(item));
        }
示例#3
0
        /// <summary>
        /// Gets index of given item
        /// </summary>
        /// <param name="item">Item whose index is required</param>
        /// <returns>index of item</returns>
        public int IndexOf(CacheBox <T> item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(_cachedData.IndexOf(item));
        }
示例#4
0
        /// <summary>
        /// pass file block index to get the data from cache
        /// </summary>
        /// <param name="blockIndex">block index</param>
        /// <returns>Return the data from block</returns>
        public T GetData(int blockIndex)
        {
            if (blockIndex <= -1)
            {
                throw new ArgumentOutOfRangeException("blockIndex");
            }

            CacheBox <T> block = this[blockIndex];

            return(block.Data);
        }
示例#5
0
        /// <summary>
        /// add into cached data
        /// </summary>
        /// <param name="item">cachebox item</param>
        public void Add(CacheBox <T> item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (_cachedData.Count >= MaxNumberOfBlocks && _timeout > 0)
            {
                ClearStaleData();
            }

            _cachedData.Add(item);
        }
示例#6
0
        /// <summary>
        /// Insert into cached data
        /// </summary>
        /// <param name="index">index at which item has to be inserted</param>
        /// <param name="item">cachebox item</param>
        public void Insert(int index, CacheBox <T> item)
        {
            if (index <= -1)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _cachedData.Insert(index, item);
        }
示例#7
0
        /// <summary>
        /// add block of data into cache
        /// </summary>
        /// <param name="blockType">Block Type</param>
        /// <param name="startRange">Block starting index</param>
        /// <param name="endRange">Block ending index</param>
        public void AddData(T blockType, long startRange, long endRange)
        {
            if (blockType == null)
            {
                throw new ArgumentNullException("blockType");
            }

            if (startRange <= -1)
            {
                throw new ArgumentOutOfRangeException("startRange");
            }

            if (endRange <= -1)
            {
                throw new ArgumentOutOfRangeException("endRange");
            }

            if (startRange >= endRange)
            {
                throw new ArgumentOutOfRangeException("startRange");
            }

            if (_cachedData.Count >= MaxNumberOfBlocks && _timeout > 0)
            {
                ClearStaleData();
            }

            CacheBox <T> block = new CacheBox <T>(endRange - startRange + 1)
            {
                StartRange = startRange,
                EndRange   = endRange,
                Data       = blockType
            };

            _cachedData.Add(block);
        }