Пример #1
0
        public void InsertToCacheWhenBufferIsFullThrowsException()
        {
            long byteCapacity = 10;
            var  typeCache    = new GCache <Type[], Type>(byteCapacity, new ArrayTypeEquality());

            //this will fill up the buffer
            typeCache.Add(new Type[] { typeof(string) }, typeof(int));
        }
Пример #2
0
        public void RaiseUsedMemoryChangedEvent(GCache <TKey, TCached> sender, CacheEventArgs <TKey, TCached> args)
        {
            var handler = OnUsedMemoryEvent;

            if (handler != null)
            {
                handler(sender, args);
            }
        }
Пример #3
0
        public void RaiseAddEvent(GCache <TKey, TCached> sender, CacheEventArgs <TKey, TCached> args)
        {
            var handler = OnAddEvent;

            if (handler != null)
            {
                handler(sender, args);
            }
        }
Пример #4
0
        public void CacheLookupTest()
        {
            long byteCapacity = 100000;
            var  typeCache    = new GCache <Type[], Type>(byteCapacity, new ArrayTypeEquality());

            var typeKey   = new Type[] { typeof(string), typeof(int) };
            var typeValue = typeof(int);

            typeCache.Add(typeKey, typeValue);
            typeCache.Add(new Type[] { typeof(int) }, typeof(string));
            typeCache.Add(new Type[] { typeof(string), typeof(float) }, typeof(string));
            typeCache.Add(new Type[] { typeof(object), typeof(int) }, typeof(string));

            var lookupResult = typeCache.Lookup(typeKey);

            Assert.AreEqual(typeValue, lookupResult);
        }
Пример #5
0
        public void CacheDeallocatesLeastIteratedEntryTest()
        {
            long byteCapacity = 2200;
            var  typeCache    = new GCache <Type[], Type>(byteCapacity, new ArrayTypeEquality());

            typeCache.Events.OnUsedMemoryEvent += ((sender, args) => Trace.WriteLine(args.ByteSize));

            var typeKey   = new Type[] { typeof(string), typeof(int) };
            var typeValue = typeof(int);

            typeCache.Add(typeKey, typeValue);
            typeCache.Add(new Type[] { typeof(int) }, typeof(string));
            typeCache.Add(new Type[] { typeof(string), typeof(float) }, typeof(string));

            var lookupResult = typeCache.Lookup(typeKey);

            typeCache.Add(new Type[] { typeof(object), typeof(int) }, typeof(string));

            Assert.AreEqual(typeValue, lookupResult);
        }
Пример #6
0
 public PocoTypeFactory(IPocoBuilder pocoBuilder)
 {
     this.pocoBuilder = pocoBuilder;
     //Initialize an unmanaged cache with buffer the 1/10 of the current memory
     cache = new GCache <Type[], Type>(GC.GetTotalMemory(true) / 10, new ArrayTypeEquality());
 }