コード例 #1
0
 public CN()
 {
     RegionsCache = LazyCache.Create(() => {
         var fileStorage = Application.Ioc.Resolve <IFileStorage>();
         var json        = fileStorage.GetResourceFile("texts", "regions_cn.json").ReadAllText();
         return(JsonConvert.DeserializeObject <List <Regions.Region> >(json));
     });
 }
コード例 #2
0
ファイル: JP.cs プロジェクト: xiaopohou/ZKWeb.Plugins
 public JP()
 {
     RegionsCache = LazyCache.Create(() => {
         var pathManager = Application.Ioc.Resolve <PathManager>();
         var path        = pathManager.GetResourceFullPath("texts", "regions_jp.json");
         var json        = File.ReadAllText(path);
         return(JsonConvert.DeserializeObject <List <Model.Region> >(json));
     });
 }
コード例 #3
0
        public void Test()
        {
            var instance = LazyCache <ITestType> .Create(() => new TestType());

            var message1 = instance.Message;

            var message2 = instance.Message;

            Assert.StartsWith("Test ", message1);

            Assert.Equal(message1, message2);
        }
コード例 #4
0
 /// <summary>
 /// 初始化
 /// </summary>
 public Country()
 {
     RegionsCache     = LazyCache.Create(() => new List <Regions.Region>());
     RegionsTreeCache = LazyCache.Create(() => {
         var regions        = RegionsCache.Value;
         var regionsMapping = regions.ToDictionary(r => r.Id);
         return(TreeUtils.CreateTree(regions,
                                     r => r, r => regionsMapping.GetOrDefault(r.ParentId)));
     });
     RegionsTreeNodeCache = LazyCache.Create(() => {
         var tree = GetRegionsTree();
         return(tree.EnumerateAllNodes()
                .Where(n => n.Value != null).ToDictionary(n => n.Value.Id));
     });
 }
コード例 #5
0
ファイル: LazyCacheTest.cs プロジェクト: fengyizhan/ZKWeb-1
        public void All()
        {
            var createCount = 0;
            var cache       = LazyCache.Create(() => { createCount += 1; return(new object()); });

            Assert.IsTrue(!cache.IsValueCreated);
            var a = cache.Value;
            var b = cache.Value;

            Assert.IsTrue(cache.IsValueCreated);
            Assert.Equals(createCount, 1);
            Assert.IsTrue(object.ReferenceEquals(a, b));

            cache.Reset();
            Assert.IsTrue(!cache.IsValueCreated);
            a = cache.Value;
            b = cache.Value;
            Assert.IsTrue(cache.IsValueCreated);
            Assert.Equals(createCount, 2);
            Assert.IsTrue(object.ReferenceEquals(a, b));
        }
コード例 #6
0
 /// <summary>
 /// 初始化
 /// </summary>
 public CurrencyManager()
 {
     CurrencyCache = LazyCache.Create(() => {
         return(Application.Ioc.ResolveMany <ICurrency>().ToDictionary(c => c.Type));
     });
 }