Beispiel #1
0
 private void deleteOldest()
 {
     lock (cacheLock)
     {
         while (hashtable.Count >= CACHE_SIZE)
         {
             CasheLine line = (CasheLine)queue.Dequeue();
             hashtable.Remove(line.key);
         }
     }
 }
Beispiel #2
0
        public List <Trip> getDataFromCache(String query)
        {
            CasheLine result = null;
            String    key    = query;

            lock (cacheLock)
            {
                if (!hashtable.ContainsKey(key))
                {
                    return(null);
                }

                result = (CasheLine)hashtable[key];
            }

            return(result.trips);
        }
Beispiel #3
0
        public void insert(string query, List <Trip> tripList)
        {
            CasheLine line = new CasheLine();

            line.key   = query;
            line.trips = tripList;

            lock (cacheLock)
            {
                if (hashtable.Count >= CACHE_SIZE)
                {
                    deleteOldest();
                }

                hashtable.Add(query, line);
                queue.Enqueue(line);
            }
        }