Exemplo n.º 1
0
        public object SampleGetByPrimary(int? id)
        {
            var cache = new BlendedCache.BlendedCache(new HttpContextCache(), new RuntimeMemoryCachingVolatileCache(), NullLongTermCache.NullInstance, new BlendedCacheConfiguration());

            id = id ?? 42;

            var dataByInt = cache.Get<SampleData>(id.Value);

            var dataByString = cache.Get<SampleData>(id.Value.ToString());

            var dataByComplex = cache.Get<SampleData, SampleComplexKey>(new SampleComplexKey());

            return dataByInt;
        }
Exemplo n.º 2
0
        public object SampleGetByCacheKey(int id)
        {
            var configuration = new BlendedCacheConfiguration();
            configuration.DefaultCacheKeyConverter = DefaultCacheKeyConverter.MyLookupKeyIsTheCacheKey;

            var cache = new BlendedCache.BlendedCache(new HttpContextCache(), new RuntimeMemoryCachingVolatileCache(), NullLongTermCache.NullInstance, configuration);

            var cacheKey = "SD." + id;

            var dataByInt = cache.Get<SampleData>(cacheKey);

            var dataByString = cache.Get<SampleData>(cacheKey);

            //complex really doesn't transfer, but it would be some string concat.
            //var dataByComplex = cache.Get<SampleData, SampleComplexKey>(new SampleComplexKey());

            return dataByInt;
        }
Exemplo n.º 3
0
        public ActionResult SampleGetByMulti()
        {
            var cache = new BlendedCache.BlendedCache(new HttpContextCache(), new RuntimeMemoryCachingVolatileCache(), NullLongTermCache.NullInstance, new BlendedCacheConfiguration());

            var ids = new List<int>() { 1, 2, 5 };

            //notice being set one at a time.
            ids.ForEach(x => cache.Set(x, DataBase.GetSampleData(x)));

            //pulled in one trip.
            var list = cache.Get<SampleData>(ids);

            return Content(list.Count.ToString());
        }