Exemple #1
0
        internal ShiroCaffeineCache(Ticker ticker, Executor maintenanceExecutor, long ttl, int maxCapacity, bool useTTL)
        {
            Caffeine <object, object> builder = Caffeine.newBuilder().maximumSize(maxCapacity).executor(maintenanceExecutor);

            if (useTTL)
            {
                if (ttl <= 0)
                {
                    throw new System.ArgumentException("TTL must be larger than zero.");
                }
                builder.ticker(ticker).expireAfterWrite(ttl, TimeUnit.MILLISECONDS);
            }
            _caffCache = builder.build();
        }
Exemple #2
0
        public static NodeFactory <K, V> NewFactory(Caffeine <K, V> builder, bool isAsync)
        {
            StringBuilder sb = new StringBuilder(10);

            if (builder.IsStrongKeys)
            {
                sb.Append('P');
            }
            else
            {
                sb.Append('F');
            }

            return(new NodeStrongKeyStrongValue <K, V>());
        }
Exemple #3
0
        public void CacheMultipleItems()
        {
            ICache <string, string> cache = Caffeine <string, string> .Builder()
                                            .SpecifyMaximumSize(2)
                                            .RecordStats()
                                            //.ExpireAfterWrite(new TimeSpan(0, 1, 0))
                                            //.RefreshAfterWrite(new TimeSpan(0, 1, 0))
                                            .Build();

            cache.Add("test", "hello world");
            cache.Add("new", "secondItem");

            string rval = cache.TryGetValue("new");

            Assert.True(!string.IsNullOrWhiteSpace(rval));
        }
Exemple #4
0
        public void CacheAndRemoveItem()
        {
            ICache <string, string> cache = Caffeine <string, string> .Builder()
                                            .SpecifyMaximumSize(100)
                                            .RecordStats()
                                            //.ExpireAfterWrite(new TimeSpan(0, 1, 0))
                                            //.RefreshAfterWrite(new TimeSpan(0, 1, 0))
                                            .Build();

            cache.Add("test", "hello world");

            cache.Invalidate("test");

            string rval = cache.TryGetValue("test");

            Assert.True(string.IsNullOrWhiteSpace(rval));
        }
Exemple #5
0
        public void CacheItem()
        {
            ICache <string, string> cache = Caffeine <string, string> .Builder()
                                            .SpecifyMaximumSize(100)
                                            .RecordStats()
                                            //.ExpireAfterWrite(new TimeSpan(0, 1, 0))
                                            //.RefreshAfterWrite(new TimeSpan(0, 1, 0))
                                            .Build();

            cache.Add("test", "hello world");

            //Thread.Sleep(5000);
            string rval = cache.TryGetValue("test");

            output.WriteLine(cache.Stats.ToString());

            Assert.Equal("hello world", rval);
        }
        public void Setup()
        {
            _receivedEventArgs = null;

            _uutCaffeine = new Caffeine();

            //#region Maybe
            //_uutCaffeine.DrinkUp(160);
            ////Kun Hvis start værdi er vigtig
            //#endregion


            _uutCaffeine.CaffeineAmountChangedEvent +=
                (sender, args) =>
            {
                //Hvad der skal ske når evented bliver triggered
                _receivedEventArgs = args;
            };
        }
Exemple #7
0
        static void Main(string[] args)
        {
            //Stress Test
            Person obj = new Person();

            Console.WriteLine("Insert your name: ");
            obj.Name = Console.ReadLine();
            Console.WriteLine("Insert your Heartbeats Per Minute: ");
            var tempBPM = Console.ReadLine();

            obj.NumberOfHeartBeatsPerMin = Convert.ToInt64(tempBPM);

            Stress objStress = new Stress();

            objStress.Stresslevel(obj);

            //Caffeine Test
            Console.WriteLine();
            Console.WriteLine();
            Caffeine Cobj = new Caffeine();

            Cobj.DrinkUp(500);
            Cobj.DrinkUp(160);
        }
 public BoundedLocalCacheStrongKeyStrongValue(Caffeine <K, V> builder, CacheLoader <K, V> loader, bool isAsync)
     : base(builder, loader, isAsync)
 {
 }
 public BoundedLocalCacheStrongKeyStrongValueListener(Caffeine <K, V> builder, CacheLoader <K, V> loader, bool isAsync)
     : base(builder, loader, isAsync)
 {
     this.RemovalListener = builder.RemovalListener;
 }
Exemple #10
0
        public BoundedLocalCache <K, V> NewBoundedLocalCache(Caffeine <K, V> builder, CacheLoader <K, V> loader, bool isAsync)
        {
            StringBuilder sb = new StringBuilder(10);

            // TODO: convert this to an enum with Flags..
            if (builder.IsStrongKeys)
            {
                sb.Append("S");
            }
            else
            {
                sb.Append("W");
            }

            if (builder.IsStrongValues)
            {
                sb.Append("S");
            }
            else
            {
                sb.Append("I");
            }

            if (builder.RemovalListener != null)
            {
                sb.Append("L");
            }

            if (builder.IsRecordingStats)
            {
                sb.Append("S");
            }

            if (builder.Evicts)
            {
                sb.Append("M");
                if (builder.IsWeighted)
                {
                    sb.Append("W");
                }
                else
                {
                    sb.Append("S");
                }
            }

            if (builder.DoesExpireAfterAccess || builder.DoesExpireVariable)
            {
                sb.Append("A");
            }

            if (builder.DoesExpireAfterWrite)
            {
                sb.Append("W");
            }

            if (builder.DoesRefreshAfterWrite)
            {
                sb.Append("R");
            }

            return((BoundedLocalCache <K, V>)Activator.CreateInstance(cacheTypes[sb.ToString()], builder, loader, isAsync));
        }