Exemple #1
0
        //获取设置的异常过期策略
        private void GetICacheItemExpiration(string interval, string assemblyName, string className, ref ICacheItemExpiration[] ie)
        {
            switch (className)
            {
            case "Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.SlidingTime":
                double dinterval = double.Parse(interval);
                ie    = new SlidingTime[1];
                ie[0] = new SlidingTime(TimeSpan.FromSeconds(dinterval));
                break;

            case "Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.AbsoluteTime":
                double          secondsAfter = double.Parse(interval);
                System.DateTime dt           = System.DateTime.Now.AddSeconds(secondsAfter);
                ie    = new AbsoluteTime[1];
                ie[0] = new AbsoluteTime(dt);
                break;

            case "Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.FileDependency":
                ie    = new FileDependency[1];
                ie[0] = new FileDependency(interval);
                break;

            case "Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.ExtendedFormatTime":
                ie    = new ExtendedFormatTime[1];
                ie[0] = new ExtendedFormatTime(interval);
                break;

            default:
                ICacheItemExpiration ieTemp = Assembly.Load(assemblyName).CreateInstance(className) as ICacheItemExpiration;
                ie    = Array.CreateInstance(ieTemp.GetType(), 1) as ICacheItemExpiration[];
                ie[0] = ieTemp;
                break;
            }
        }
Exemple #2
0
        static void Main()
        {
            var container = new UnityContainer()
                            .AddNewExtension <EnterpriseLibraryCoreExtension>();

            var cacheManager = container.Resolve <ICacheManager>();

            cacheManager.Add("demo", "demo data");

            //var absoluteTime = new AbsoluteTime(TimeSpan.FromHours(5));
            //var neverExpired = new NeverExpired();
            //var slidingTime = new SlidingTime(TimeSpan.FromSeconds(1000));
            //cacheManager.Add("demo2", "another data", CacheItemPriority.NotRemovable, null, neverExpired);

            //cacheManager.Remove("demo");
            //cacheManager.Flush();

            File.WriteAllText("C:\\temp\\tempfile.txt", "bla bla bla");

            //var fileDependency = new FileDependency("C:\\temp\\tempfile.txt");
            //cacheManager.Add("demo2", "aother demo object", CacheItemPriority.NotRemovable, null, fileDependency);

            // * * * * *
            // minute houre day month dayofweek
            // 10 12 * * 0
            var extendedPolicy = new ExtendedFormatTime("* * * *");

            cacheManager.Add("demo2", "aother demo object", CacheItemPriority.NotRemovable, null, extendedPolicy);


            var data = cacheManager.GetData("demo");

            if (data != null)
            {
                Console.WriteLine(data);
            }

            var data2 = cacheManager.GetData("demo2");

            if (data2 != null)
            {
                Console.WriteLine(data2);
            }

            File.Delete("C:\\temp\\tempfile.txt");

            data2 = cacheManager.GetData("demo2");
            if (data2 != null)
            {
                Console.WriteLine(data2);
            }

            //Thread.Sleep(20*1000);

            //data2 = cacheManager.GetData("demo2");
            //if (data2 != null) Console.WriteLine(data2);
            //else Console.WriteLine("data was gone");

            Console.ReadKey();
        }
        public void ClassCanSerializeCorrectly()
        {
            ExtendedFormatTime format = new ExtendedFormatTime("5 * * * *");

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            formatter.Serialize(stream, format);
            stream.Position = 0;
            ExtendedFormatTime format2 = (ExtendedFormatTime)formatter.Deserialize(stream);

            Assert.AreEqual(format.TimeFormat, format2.TimeFormat);
        }
Exemple #4
0
        public void ClassCanSerializeCorrectly()
        {
            ExtendedFormatTime format = new ExtendedFormatTime("5 * * * *");

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            formatter.Serialize(stream, format);
            stream.Position = 0;
            ExtendedFormatTime format2 = (ExtendedFormatTime)formatter.Deserialize(stream);

            Assert.AreEqual(format.TimeFormat, format2.TimeFormat);
        }
 public void AddCache <T>(string key, T TEntity, ExtendedFormatTime expirations)
 {
     CurrentCache.Add(key, TEntity, CacheItemPriority.Normal, null, expirations);
 }
 public void AddCache(string key, object value, ExtendedFormatTime expirations)
 {
     CurrentCache.Add(key, value, CacheItemPriority.Normal, null, expirations);
 }
Exemple #7
0
        public void ExtendFormatTimeExpiresCorrectly()
        {
            ExtendedFormatTime format = new ExtendedFormatTime("5 * * * *");

            Assert.IsFalse(format.HasExpired());
        }
Exemple #8
0
 public void NullTimeFormatThrowsException()
 {
     ExtendedFormatTime time = new ExtendedFormatTime(null);
 }
 public void ExtendFormatTimeExpiresCorrectly()
 {
     ExtendedFormatTime format = new ExtendedFormatTime("5 * * * *");
     Assert.IsFalse(format.HasExpired());
 }
 public void NullTimeFormatThrowsException()
 {
     ExtendedFormatTime time = new ExtendedFormatTime(null);
 }