コード例 #1
0
ファイル: IoC.cs プロジェクト: jonasswiatek/sleipner2
        public static IContainer Initialize()
        {
            var memcachedCluster = new MemcachedSharpClientCluster(new[] { "localhost:11211" });
            var proxy            = new SleipnerCache <ICrapService>(new CrapService(), new MemcachedProvider <ICrapService>(memcachedCluster));

            proxy.Config(a =>
            {
                a.DefaultIs().CacheFor(10);
            });

            ObjectFactory.Initialize(x =>
            {
                x.For <ICrapService>().Singleton().Use(proxy.CreateCachedInstance());
            });

            return(ObjectFactory.Container);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jonasswiatek/sleipner2
        static async Task MainAsync(string[] args)
        {
            var memcachedCluster = new MemcachedSharpClientCluster(new[] { "localhost:11211" });
            var service          = new CrapService();
            var cacheProvider    = new MemcachedProvider <ICrapService>(memcachedCluster);
            var sleipnerProxy    = new SleipnerCache <ICrapService>(service, cacheProvider);

            sleipnerProxy.Config(a => a.DefaultIs().CacheFor(1).DiscardStale());
            var cachedService = sleipnerProxy.CreateCachedInstance();

            /*while (true)
             * {
             *  var i13 = await cachedService.GetCrapAsync("", 1);
             *
             *  await cacheProvider.DeleteAsync(a => a.GetCrapAsync("", 1));
             *
             *  var i2 = await cachedService.GetCrapAsync("", 1);
             *
             *  Console.ReadLine();
             * }*/
        }
コード例 #3
0
        public static IContainer Initialize()
        {
            var options = new ConfigurationOptions {
                EndPoints = { new DnsEndPoint("dlhack03.ts1.local", 6379) }
            };

            var redisClient = new RedisClient(options);
            var proxy       = new SleipnerCache <ICrapService>(new CrapService(), new RedisProvider <ICrapService>(redisClient));

            proxy.Config(a =>
            {
                a.DefaultIs().CacheFor(10);
                a.For(x => x.GetEvenMoreCrap(Param.IsAny <int>())).CacheFor(120);
            });

            ObjectFactory.Initialize(x =>
            {
                x.For <ICrapService>().Singleton().Use(proxy.CreateCachedInstance());
            });

            return(ObjectFactory.Container);
        }