Beispiel #1
0
        /// <summary>
        /// Method for get a cache value, Throw exception if has a Miss
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public int ReadCacheValue(string tag)
        {
            int        value;
            int        position = Convert.ToInt32(tag, 2) % 2;
            CacheBlock temp     = memoryCache[position];

            if (temp.Tag == "")
            {
                throw new ColdMissCacheException();
            }
            else if (temp.Tag == tag)
            {
                if (temp.State == "I")
                {
                    throw new InvalidMissCacheException();
                }
                else
                {
                    value = temp.Value;
                }
            }
            else
            {
                throw new CorrespondenceMissCacheException();
            }
            return(value);
        }
Beispiel #2
0
        /// <summary>
        /// Validate if the position a tag given is in the Cache
        /// </summary>
        /// <param name="position"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public bool ExistCacheValue(string tag)
        {
            bool       result;
            int        position = Convert.ToInt32(tag, 2) % 2;
            CacheBlock temp     = memoryCache[position];

            result = (temp.Tag == tag) ? true : false;
            return(result);
        }
Beispiel #3
0
 /// <summary>
 /// Initialize de Cache (Cold Cache)
 /// </summary>
 public void InitializeCache()
 {
     memoryCache = new List <CacheBlock>();
     for (int i = 0; i < NUMBLOCKS; i++)
     {
         CacheBlock block = new CacheBlock()
         {
             State = "I",
             Tag   = "",
             Value = 0
         };
         memoryCache.Add(block);
     }
 }