Esempio n. 1
0
 public ClassEntry Search(uint cid)
 {
     //time consuming operations, that's the reason for cache
     if (m_cid_cache.ContainsKey(cid))
     {
         ClassEntry t = (ClassEntry)m_cid_cache[cid];
         t.BreakLinks();
         t.BuildLinks(m_LRU, m_LRU.Next);
         return(t);
     }
     else
     {
         //do the sequential search, :(
         OOD.Imp.Storage.BTree.BTEnumerator bt = m_tree.GetEnumerator();
         while (bt.MoveNext())
         {
             KCatalog key = (KCatalog)bt.Current;
             Debug.Assert(key != null);
             if (key.ClassInfo != null && key.ClassInfo.CId == cid)
             {
                 //found
                 _put_in_cache(cid, key.ClassName, key.ClassInfo.FieldNames, key.ClassInfo.TopNodeSId);
                 return((ClassEntry)m_cid_cache[cid]);
             }
         }
         return(null);
     }
 }
Esempio n. 2
0
 public ClassEntry Search(string className)
 {
     if (m_name_cache.ContainsKey(className))
     {
         ClassEntry result = (ClassEntry)m_name_cache[className];
         result.BreakLinks();
         result.BuildLinks(m_LRU, m_LRU.Next);
         return(result);
     }
     else
     {
         //not in cache, get it from disk
         KCatalog target = new KCatalog(className);
         KCatalog t      = (KCatalog)m_tree.Search(target);
         if (t != null)
         {
             _put_in_cache(t.ClassInfo.CId, className, t.ClassInfo.FieldNames, t.ClassInfo.TopNodeSId);
             return((ClassEntry)m_cid_cache[t.ClassInfo.CId]);
         }
         else
         {
             return(null);
         }
     }
 }
Esempio n. 3
0
        internal void _put_in_cache(uint cid, string className, string[] fields, uint topNodeSId)
        {
            Debug.Assert(m_name_cache.Count == m_cid_cache.Count);

            if (m_name_cache.Count > m_cache_limit)
            {
                //kick one out needed
                ClassEntry victim = m_LRU.Previous;

                Debug.Assert(victim != null);

                victim.BreakLinks();                 //remove from LRU list
                m_name_cache.Remove(victim.ClassName);
                m_cid_cache.Remove(victim.CId);
            }

            ClassEntry ce = new ClassEntry(cid, className, fields, topNodeSId);

            m_name_cache.Add(className, ce);
            m_cid_cache.Add(cid, ce);
            ce.BuildLinks(m_LRU, m_LRU.Next);             //put it to the front of the list, -- most recently used
        }
Esempio n. 4
0
		internal void _put_in_cache(uint cid, string className, string[] fields, uint topNodeSId)
		{
			Debug.Assert(m_name_cache.Count == m_cid_cache.Count);

			if (m_name_cache.Count > m_cache_limit)
			{
				//kick one out needed
				ClassEntry victim = m_LRU.Previous;

				Debug.Assert(victim != null);

				victim.BreakLinks(); //remove from LRU list
				m_name_cache.Remove(victim.ClassName);
				m_cid_cache.Remove(victim.CId);
			}
			
			ClassEntry ce = new ClassEntry(cid, className, fields, topNodeSId);
			m_name_cache.Add(className, ce);
			m_cid_cache.Add(cid, ce);
			ce.BuildLinks(m_LRU, m_LRU.Next); //put it to the front of the list, -- most recently used
		}