コード例 #1
0
        public void SetSync <K, V>(KVCacheVisitor visitor, K key, V value)
        {
            var prefix      = GetPrefix(visitor.Name, typeof(K), typeof(V));
            var realService = getRealService(visitor.CacheType);

            realService.SetSync(visitor.CacheConfiguration, prefix, key, value);
        }
コード例 #2
0
ファイル: CacheInnerHelper.cs プロジェクト: rhw1111/DCEM
        public static KVCacheVisitor CreateKVCacheVisitor(KVCacheVisitorSetting setting)
        {
            KVCacheVisitor visitor;

            switch (setting.KVCacheType)
            {
            case KVCacheTypes.LocalTimeout:
                visitor = new KVCacheVisitor()
                {
                    Name               = setting.Name,
                    CacheType          = KVCacheTypes.LocalTimeout,
                    CacheConfiguration = string.Format(@"{{
                        ""MaxLength"":{0},
                        ""ExpireSeconds"":{1}
                }}", setting.MaxLength.ToString(), setting.ExpireSeconds.ToString())
                };
                break;

            default:
                visitor = new KVCacheVisitor()
                {
                    Name               = setting.Name,
                    CacheType          = KVCacheTypes.LocalVersion,
                    CacheConfiguration = string.Format(@"{{
                        ""MaxLength"":{0},
                        ""VersionCallTimeout"":{1},
                        ""VersionNameMappings"":{{}},
                        ""DefaultVersionName"":{2}
                }}", setting.MaxLength.ToString(), setting.VersionCallTimeout.ToString(), setting.VersionName)
                };
                break;
            }

            return(visitor);
        }
コード例 #3
0
        public V GetSync <K, V>(KVCacheVisitor visitor, Func <K, V> creator, K key)
        {
            var prefix      = GetPrefix(visitor.Name, typeof(K), typeof(V));
            var realService = getRealService(visitor.CacheType);

            return(realService.GetSync(visitor.CacheConfiguration,
                                       () =>
            {
                return creator(key);
            }
                                       , prefix, key));
        }
コード例 #4
0
        public async Task <V> Get <K, V>(KVCacheVisitor visitor, Func <K, Task <V> > creator, K key)
        {
            var prefix      = GetPrefix(visitor.Name, typeof(K), typeof(V));
            var realService = getRealService(visitor.CacheType);

            return(await realService.Get(visitor.CacheConfiguration,
                                         async() =>
            {
                return await creator(key);
            }
                                         , prefix, key));
        }
コード例 #5
0
 public async Task Set <K, V>(KVCacheVisitor visitor, K key, V value)
 {
     var prefix      = GetPrefix(visitor.Name, typeof(K), typeof(V));
     var realService = getRealService(visitor.CacheType);
     await realService.Set(visitor.CacheConfiguration, prefix, key, value);
 }