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); }
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); }
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)); }
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)); }
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); }