78 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| 
 | |
| namespace AIMSExtension
 | |
| {
 | |
| 	public static class MyCache
 | |
| 	{
 | |
| 		private static Dictionary<int, object> dicCache = new Dictionary<int, object>();
 | |
| 
 | |
| 		private static Dictionary<int, DateTime> dicTimeout = new Dictionary<int, DateTime>();
 | |
| 
 | |
| 		public static object GetCacheInfo(string key)
 | |
| 		{
 | |
| 			int hashCode = key.GetHashCode();
 | |
| 			return MyCache.GetCacheInfo(hashCode);
 | |
| 		}
 | |
| 
 | |
| 		public static object GetCacheInfo(int hash)
 | |
| 		{
 | |
| 			bool flag = MyCache.dicCache.ContainsKey(hash);
 | |
| 			object result;
 | |
| 			if (flag)
 | |
| 			{
 | |
| 				bool flag2 = MyCache.dicTimeout[hash].CompareTo(DateTime.Now) > 0;
 | |
| 				if (flag2)
 | |
| 				{
 | |
| 					result = MyCache.dicCache[hash];
 | |
| 					return result;
 | |
| 				}
 | |
| 				MyCache.dicCache.Remove(hash);
 | |
| 				MyCache.dicTimeout.Remove(hash);
 | |
| 			}
 | |
| 			result = null;
 | |
| 			return result;
 | |
| 		}
 | |
| 
 | |
| 		public static int SetCacheInfo(string key, object value, int timeout = 300)
 | |
| 		{
 | |
| 			int hashCode = key.GetHashCode();
 | |
| 			return MyCache.SetCacheInfo(hashCode, value, timeout);
 | |
| 		}
 | |
| 
 | |
| 		public static int SetCacheInfo(int hash, object value, int timeout = 300)
 | |
| 		{
 | |
| 			MyCache.dicTimeout[hash] = DateTime.Now.AddSeconds((double)timeout);
 | |
| 			MyCache.dicCache[hash] = value;
 | |
| 			return hash;
 | |
| 		}
 | |
| 
 | |
| 		public static int Remove(string key)
 | |
| 		{
 | |
| 			int hashCode = key.GetHashCode();
 | |
| 			return MyCache.Remove(hashCode);
 | |
| 		}
 | |
| 
 | |
| 		public static int Remove(int hash)
 | |
| 		{
 | |
| 			bool flag = MyCache.dicCache.ContainsKey(hash);
 | |
| 			int result;
 | |
| 			if (flag)
 | |
| 			{
 | |
| 				MyCache.dicCache.Remove(hash);
 | |
| 				result = hash;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				result = 0;
 | |
| 			}
 | |
| 			return result;
 | |
| 		}
 | |
| 
 | |
| 		public static void Clear()
 | |
| 		{
 | |
| 			MyCache.dicCache.Clear();
 | |
| 		}
 | |
| 	}
 | |
| }
 |