Exemple #1
0
        public ActionResult LoadData()
        {
            RedisCacheProvider cacheProvider = new RedisCacheProvider();

            List <VueTestModel> basicData = new List <VueTestModel>();

            //Dictionary<string, VueTestModel> dic = new Dictionary<string, VueTestModel>();

            if (!cacheProvider.Exists("VueTest:LoadData:VueTestModel"))
            {
                basicData = new List <VueTestModel>
                {
                    new VueTestModel {
                        Name = "rico", Age = 35, Birthday = DateTime.Now.ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "sherry", Age = 30, Birthday = DateTime.Now.AddDays(-1).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "fifi", Age = 4, Birthday = DateTime.Now.AddMonths(-10).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "rico2", Age = 34, Birthday = DateTime.Now.AddDays(-2).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "sherry2", Age = 29, Birthday = DateTime.Now.AddDays(-2).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "fifi2", Age = 3, Birthday = DateTime.Now.AddMonths(-20).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "rico3", Age = 33, Birthday = DateTime.Now.AddDays(-3).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "sherry3", Age = 28, Birthday = DateTime.Now.AddDays(-3).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "fifi3", Age = 2, Birthday = DateTime.Now.AddMonths(-30).ToShortDateString()
                    },
                    new VueTestModel {
                        Name = "Vue", Age = 1, Birthday = DateTime.Now.AddMonths(-60).ToShortDateString()
                    }
                };
            }


            var cache = cacheProvider.ListGetOrSave <VueTestModel>("VueTest:LoadData:VueTestModel", basicData);
            //var cache = cacheProvider.GetOrSet<List<VueTestModel>>("VueTest:VueTestModel", basicData);

            var result = JsonConvert.SerializeObject(cache);

            return(Json(result));
        }