public virtual void TestThreadCorrectness() { const int NUM_THREADS = 4; const int CACHE_SIZE = 512; int OBJ_COUNT = 3 * CACHE_SIZE; DoubleBarrelLRUCache <CloneableObject, object> c = new DoubleBarrelLRUCache <CloneableObject, object>(1024); CloneableObject[] objs = new CloneableObject[OBJ_COUNT]; for (int i = 0; i < OBJ_COUNT; i++) { objs[i] = new CloneableObject(new object()); } CacheThread[] threads = new CacheThread[NUM_THREADS]; DateTime endTime = DateTime.Now.AddSeconds(1); for (int i = 0; i < NUM_THREADS; i++) { threads[i] = new CacheThread(this, c, objs, endTime); threads[i].Start(); } for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); Assert.False(threads[i].failed); } //System.out.println("hits=" + totHit + " misses=" + totMiss); }
public virtual void TestThreadCorrectness() { const int NUM_THREADS = 4; const int CACHE_SIZE = 512; int OBJ_COUNT = 3 * CACHE_SIZE; DoubleBarrelLRUCache<CloneableObject, object> c = new DoubleBarrelLRUCache<CloneableObject, object>(1024); CloneableObject[] objs = new CloneableObject[OBJ_COUNT]; for (int i = 0; i < OBJ_COUNT; i++) { objs[i] = new CloneableObject(new object()); } CacheThread[] threads = new CacheThread[NUM_THREADS]; DateTime endTime = DateTime.Now.AddSeconds(1); for (int i = 0; i < NUM_THREADS; i++) { threads[i] = new CacheThread(this, c, objs, endTime); threads[i].Start(); } for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); Assert.False(threads[i].Failed); } //System.out.println("hits=" + totHit + " misses=" + totMiss); }
public virtual void TestThreadCorrectness() { const int NUM_THREADS = 4; const int CACHE_SIZE = 512; int OBJ_COUNT = 3 * CACHE_SIZE; DoubleBarrelLRUCache <CloneableObject, object> c = new DoubleBarrelLRUCache <CloneableObject, object>(1024); CloneableObject[] objs = new CloneableObject[OBJ_COUNT]; for (int i = 0; i < OBJ_COUNT; i++) { objs[i] = new CloneableObject(new object()); } CacheThread[] threads = new CacheThread[NUM_THREADS]; long endTime = (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) + 1000L; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results for (int i = 0; i < NUM_THREADS; i++) { threads[i] = new CacheThread(this, c, objs, endTime); threads[i].Start(); } for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); Assert.False(threads[i].failed); } //System.out.println("hits=" + totHit + " misses=" + totMiss); }
public static void CacheTest() { //查询数据源 List <Person> personData = new List <Person>(); personData.Add(new Person() { Id = Guid.NewGuid(), Code = "101", Name = "张三" }); //放进缓存 默认2分半钟自动释放 var cachePersonData = new CacheThread <List <Person> >(personData); //从缓存取数据 personData = cachePersonData.DictionaryData; }
/// <summary> /// Raises the CacheError event. /// This method is invoked from the thumbnail thread. /// </summary> /// <param name="guid">The Guid of the ImageListViewItem that is associated with this error. /// This parameter can be null.</param> /// <param name="error">The error that occurred during an asynchronous operation.</param> /// <param name="cacheThread">The thread raising the error.</param> internal void OnCacheErrorInternal(Guid guid, Exception error, CacheThread cacheThread) { ImageListViewItem item = null; mItems.TryGetValue(guid, out item); OnCacheError(new CacheErrorEventArgs(item, error, cacheThread)); }
/// <summary> /// Initializes a new instance of the CacheErrorEventArgs class. /// </summary> /// <param name="item">The ImageListViewItem that is associated with this error.</param> /// <param name="error">The error that occurred during an asynchronous operation.</param> /// <param name="cacheThread">The thread raising the error.</param> public CacheErrorEventArgs(ImageListViewItem item, Exception error, CacheThread cacheThread) { Item = item; Error = error; CacheThread = cacheThread; }