当前位置: 首页>>代码示例>>C#>>正文


C# ICacheManager.Add方法代码示例

本文整理汇总了C#中ICacheManager.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheManager.Add方法的具体用法?C# ICacheManager.Add怎么用?C# ICacheManager.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICacheManager的用法示例。


在下文中一共展示了ICacheManager.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoginViewModel

        public LoginViewModel(INavigationService navigateService, GithubApiService ghservice, INotificationController notController, ICacheManager cache)
        {
            IsLogin = false;
            NavigationService = navigateService;
            GHService = ghservice;
            NotificationController = notController;
            _cache = cache;

            _loginCommand = new DelegateCommand(() =>
            {

                NotificationController.SplashScreen.IsVisible = true;
                cache.Add("username", User);
                cache.Add("password", Password);
                GHService.UseCredentials(User, Password);
                NavigationService.Navigate(AppPages.MainPage);
            });
        }
开发者ID:IvanKuzavkov,项目名称:gitfoot,代码行数:18,代码来源:LoginViewModel.cs

示例2: CacheManagerTest

        void CacheManagerTest(ICacheManager mgr)
        {
            string key = "key1";
            string val = "value123";

            Assert.IsNull(mgr.GetData(key));

            mgr.Add(key, val);

            string result = (string)mgr.GetData(key);
            Assert.AreEqual(val, result, "result");
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:12,代码来源:SymmetricStorageEncryptionProviderFixture.cs

示例3: Thread_Update

        public void Thread_Update(ICacheManager<object> cache)
        {
            using (cache)
            {
                var key = Guid.NewGuid().ToString();
                var handleInfo = string.Join("\nh: ", cache.CacheHandles.Select(p => p.Configuration.Name + ":" + p.GetType().Name));

                cache.Remove(key);
                cache.Add(key, new RaceConditionTestElement() { Counter = 0 });
                int numThreads = 5;
                int iterations = 10;
                int numInnerIterations = 10;
                int countCasModifyCalls = 0;

                // act
                ThreadTestHelper.Run(
                    () =>
                    {
                        for (int i = 0; i < numInnerIterations; i++)
                        {
                            cache.Update(key, (value) =>
                            {
                                var val = (RaceConditionTestElement)value;
                                val.Counter++;
                                Interlocked.Increment(ref countCasModifyCalls);
                                return value;
                            });
                        }
                    },
                    numThreads,
                    iterations);

                // assert
                Thread.Sleep(10);
                for (var i = 0; i < cache.CacheHandles.Count(); i++)
                {
                    var handle = cache.CacheHandles.ElementAt(i);
                    var result = (RaceConditionTestElement)handle.Get(key);
                    if (i < cache.CacheHandles.Count() - 1)
                    {
                        // only the last one should have the item
                        result.Should().BeNull();
                    }
                    else
                    {
                        result.Should().NotBeNull(handleInfo + "\ncurrent: " + handle.Configuration.Name + ":" + handle.GetType().Name);
                        result.Counter.Should().Be(numThreads * numInnerIterations * iterations, handleInfo + "\ncounter should be exactly the expected value.");
                        countCasModifyCalls.Should().BeGreaterOrEqualTo((int)result.Counter, handleInfo + "\nexpecting no (if synced) or some version collisions.");
                    }
                }
            }
        }
开发者ID:yue-shi,项目名称:CacheManager,代码行数:52,代码来源:ThreadRandomReadWriteTestBase.cs

示例4: GetProductData

        public List<Product> GetProductData(out string cacheStatus)
        {
            cacheProductData = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>();
            listProducts = (List<Product>)cacheProductData["ProductDataCache"];
            cacheStatus = "Employee Information is Retrived from Cache";
            LetsShopImplementation ls = new LetsShopImplementation();
            CacheFlag = true;
            if (listProducts == null)
            {
              //Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("LetsShopConnection");
              //listProducts =

                LetsShopImplementation ls = new LetsShopImplementation();
                listProducts = ls.GetProducts();
                AbsoluteTime CacheExpirationTime = new AbsoluteTime(new TimeSpan(1, 0, 0));
                cacheProductData.Add("ProductDataCache", listProducts, CacheItemPriority.High, null, new ICacheItemExpiration[] { CacheExpirationTime });
                cacheStatus = "Product Info is Added in cache";
                CacheFlag = false;
            }
            return listProducts;
        }
开发者ID:Nagendra12122,项目名称:MVC3-Order-Management-System,代码行数:21,代码来源:CachingImplementation.cs

示例5: LoadAttribute

        public static void LoadAttribute(List<string> BusinessDll, ICacheManager cache, string pluginName)
        {
            List<WebServicesAttributeInfo> webserviceList = new List<WebServicesAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WebServiceAttribute[] webS = ((WebServiceAttribute[])types[i].GetCustomAttributes(typeof(WebServiceAttribute), true));
                    if (webS.Length > 0)
                    {
                        WebServicesAttributeInfo wsa = new WebServicesAttributeInfo();
                        wsa.ServiceName = types[i].Name;
                        wsa.ServiceType = types[i];
                        webserviceList.Add(wsa);
                    }
                }
            }

            cache.Add(pluginName+"@"+GetCacheKey(), webserviceList);
        }
开发者ID:keep01,项目名称:efwplus_winformframe,代码行数:23,代码来源:WebServicesManager.cs

示例6: Run

            public StateHash Run(DeployContext context, StateHash hash, ICacheManager cacheManager, bool first = true, bool last = true)
            {
                if (mLogPre != null)
                    context.ApplicationContext.Log.Log(mLogPre);

                if (mTransform != null)
                {
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    hash = mTransform.RunTransform(hash, context.DryRun, context.ApplicationContext.Log);
                    stopWatch.Stop();

                    if (!context.DryRun)
                    {
                        var rhf = GetResumeHashFile(context);
                        File.WriteAllText(rhf.FullName, hash.ToHexString());
                    }

                    if (!first && !last && stopWatch.Elapsed >= context.ApplicationContext.UserConfig.Cache.MinDeployTime)
                    {
                        foreach (var db in context.ApplicationContext.ProjectConfig.Databases)
                        {
                            cacheManager.Add(context.ApplicationContext.UserConfig.Databases.Connection, db, hash);
                        }
                    }
                }
                else if (mChildren.Count > 0)
                {
                    using (context.ApplicationContext.Log.IndentScope())
                    {
                        for (var i = 0; i < mChildren.Count; i++)
                        {
                            var child = mChildren[i];
                            hash = child.Run(context, hash, cacheManager, first, last && i == mChildren.Count - 1);
                            first = false;
                        }
                    }
                }

                if (mLogPost != null)
                    context.ApplicationContext.Log.Log(mLogPost);

                return hash;
            }
开发者ID:aiedail92,项目名称:DBBranchManager,代码行数:44,代码来源:DbbmDeployCommand.cs

示例7: TestEachMethod

        public static void TestEachMethod(ICacheManager<object> cache)
        {
            cache.Clear();

            cache.Add("key", "value", "region");
            cache.AddOrUpdate("key", "region", "value", _ => "update value", 22);

            cache.Expire("key", "region", TimeSpan.FromDays(1));
            var val = cache.Get("key", "region");
            var item = cache.GetCacheItem("key", "region");
            cache.Put("key", "put value");
            cache.RemoveExpiration("key");

            object update2;
            cache.TryUpdate("key", "region", _ => "update 2 value", out update2);

            object update3 = cache.Update("key", "region", _ => "update 3 value");

            cache.Remove("key", "region");

            cache.Clear();
            cache.ClearRegion("region");
        }
开发者ID:yue-shi,项目名称:CacheManager,代码行数:23,代码来源:Tests.cs

示例8: LoadAttribute

        /// <summary>
        /// 加载自定义标签
        /// </summary>
        /// <param name="BusinessDll">Dll路径</param>
        /// <param name="cache">存入缓存</param>
        public static void LoadAttribute(List<string> BusinessDll, ICacheManager cache,string pluginName)
        {
            string cacheKey = pluginName+"@"+GetCacheKey();

            List<EntityAttributeInfo> entityAttributeList = new List<EntityAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {

                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    TableAttribute[] tableAttrs = ((TableAttribute[])types[i].GetCustomAttributes(typeof(TableAttribute), true));

                    if (tableAttrs.Length > 0)
                    {
                        EntityAttributeInfo eattr = new EntityAttributeInfo();
                        eattr.ObjType = types[i];
                        eattr.TableAttributeInfoList = new List<TableAttributeInfo>();
                        foreach (TableAttribute val in tableAttrs)
                        {
                            TableAttributeInfo tableattr = new TableAttributeInfo();
                            tableattr.Alias = val.Alias;
                            tableattr.EType = val.EntityType;
                            tableattr.TableName = val.TableName;
                            tableattr.IsGB = val.IsGB;
                            tableattr.ColumnAttributeInfoList = new List<ColumnAttributeInfo>();

                            PropertyInfo[] property = eattr.ObjType.GetProperties();
                            for (int n = 0; n < property.Length; n++)
                            {
                                ColumnAttribute[] columnAttributes = (ColumnAttribute[])property[n].GetCustomAttributes(typeof(ColumnAttribute), true);
                                if (columnAttributes.Length > 0)
                                {
                                    ColumnAttributeInfo colattr = new ColumnAttributeInfo();
                                    ColumnAttribute colval = columnAttributes.ToList().Find(x => x.Alias == tableattr.Alias);
                                    if (colval == null) throw new Exception("输入的Alias别名不正确");
                                    colattr.Alias = colval.Alias;
                                    colattr.DataKey = colval.DataKey;
                                    colattr.FieldName = colval.FieldName;
                                    colattr.IsInsert = colval.IsInsert;
                                    //colattr.IsSingleQuote=colval.is
                                    colattr.Match = colval.Match;
                                    colattr.PropertyName = property[n].Name;

                                    if (colattr.DataKey)
                                    {
                                        tableattr.DataKeyFieldName = colattr.FieldName;//设置TableAttributeInfo的主键字段名
                                        tableattr.DataKeyPropertyName = colattr.PropertyName;
                                    }
                                    tableattr.ColumnAttributeInfoList.Add(colattr);
                                }
                            }

                            eattr.TableAttributeInfoList.Add(tableattr);
                        }


                        entityAttributeList.Add(eattr);
                    }
                }
            }

            cache.Add(cacheKey, entityAttributeList);
        }
开发者ID:keep01,项目名称:efwplus_winformframe,代码行数:71,代码来源:EntityManager.cs

示例9: CacheThreadTest

        public static void CacheThreadTest(ICacheManager<string> cache, int seed)
        {
            var threads = 10;
            var numItems = 100;
            var eventAddCount = 0;
            var eventRemoveCount = 0;
            var eventGetCount = 0;

            cache.OnAdd += (sender, args) => { Interlocked.Increment(ref eventAddCount); };
            cache.OnRemove += (sender, args) => { Interlocked.Increment(ref eventRemoveCount); };
            cache.OnGet += (sender, args) => { Interlocked.Increment(ref eventGetCount); };

            Func<int, string> keyGet = (index) => "key" + ((index + 1) * seed);

            Action test = () =>
            {
                for (int i = 0; i < numItems; i++)
                {
                    cache.Add(keyGet(i), i.ToString());
                }

                for (int i = 0; i < numItems; i++)
                {
                    if (i % 10 == 0)
                    {
                        cache.Remove(keyGet(i));
                    }
                }

                for (int i = 0; i < numItems; i++)
                {
                    string val = cache.Get(keyGet(i));
                }
            };

            Parallel.Invoke(new ParallelOptions() { MaxDegreeOfParallelism = 8 }, Enumerable.Repeat(test, threads).ToArray());

            foreach (var handle in cache.CacheHandles)
            {
                var stats = handle.Stats;
                Console.WriteLine(string.Format(
                        "Items: {0}, Hits: {1}, Miss: {2}, Remove: {3}, ClearRegion: {4}, Clear: {5}, Adds: {6}, Puts: {7}, Gets: {8}",
                            stats.GetStatistic(CacheStatsCounterType.Items),
                            stats.GetStatistic(CacheStatsCounterType.Hits),
                            stats.GetStatistic(CacheStatsCounterType.Misses),
                            stats.GetStatistic(CacheStatsCounterType.RemoveCalls),
                            stats.GetStatistic(CacheStatsCounterType.ClearRegionCalls),
                            stats.GetStatistic(CacheStatsCounterType.ClearCalls),
                            stats.GetStatistic(CacheStatsCounterType.AddCalls),
                            stats.GetStatistic(CacheStatsCounterType.PutCalls),
                            stats.GetStatistic(CacheStatsCounterType.GetCalls)));
            }

            Console.WriteLine(string.Format("Event - Adds {0} Hits {1} Removes {2}",
                eventAddCount,
                eventGetCount,
                eventRemoveCount));

            cache.Clear();
            cache.Dispose();
        }
开发者ID:huoxudong125,项目名称:CacheManager,代码行数:61,代码来源:Tests.cs

示例10: TestEachMethod

        public static void TestEachMethod(ICacheManager<object> cache)
        {
            cache.Clear();

            cache.Add("key", "value", "region");
            cache.AddOrUpdate("key", "region", "value", _ => "update value", new UpdateItemConfig(2, VersionConflictHandling.EvictItemFromOtherCaches));

            cache.Expire("key", "region", TimeSpan.FromDays(1));
            var val = cache.Get("key", "region");
            var item = cache.GetCacheItem("key", "region");
            cache.Put("key", "region", "put value");
            cache.RemoveExpiration("key", "region");

            object update2;
            cache.TryUpdate("key", "region", _ => "update 2 value", out update2);

            object update3 = cache.Update("key", "region", _ => "update 3 value");

            cache.Remove("key", "region");

            cache.Clear();
            cache.ClearRegion("region");
        }
开发者ID:serkanpektas,项目名称:CacheManager,代码行数:23,代码来源:Tests.cs

示例11: GetContentHTMLEventDef

        /// <summary>
        /// This will return the Content HTML Event Definition, which is a combination of ContentData properties and MetaDataProperties.
        /// </summary>
        /// <returns></returns>
        private EventDefinition GetContentHTMLEventDef()
        {
            Log.WriteMessage(string.Format("-Begin {0}.GetContentHTMLEventDef.", CLASS_NAME), LogLevel.Verbose);
            EventDefinition HTMLDefinition = null;
            try
            {

                CachManger = ObjectFactory.GetCacheManager();
                HTMLDefinition = CachManger.Get(CacheKey) as EventDefinition;

                if (HTMLDefinition == null)
                {

                    List<EventDefinition> EktronEventDefs = null;

                    if (!string.IsNullOrEmpty(AdapterName))
                    {
                        EktronEventDefs = this.ContextBusClient.GetEventDefinitionList(AdapterName);
                    }
                    if (EktronEventDefs != null)
                    {
                        HTMLDefinition = EktronEventDefs.FirstOrDefault(x => x.DisplayName.ToLower().Contains("html"));
                        CachManger.Add(CacheKey, HTMLDefinition, new TimeSpan(0, 10, 0));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError(string.Format("{0}.GetContentHTMLEventDef failed: {1}.", CLASS_NAME, ex.Message));
            }

            Log.WriteMessage(string.Format("+Finish {0}.GetContentHTMLEventDef.", CLASS_NAME), LogLevel.Verbose);
            return HTMLDefinition;
        }
开发者ID:femiosinowo,项目名称:sssadl,代码行数:38,代码来源:DxHContentHTMLStrategy.cs

示例12: Thread_RandomAccess

        public void Thread_RandomAccess(ICacheManager<object> cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            foreach (var handle in cache.CacheHandles)
            {
                Trace.TraceInformation("Using handle {0}", handle.GetType());
            }

            var blob = new byte[1024];

            using (cache)
            {
                Action test = () =>
                {
                    var hits = 0;
                    var misses = 0;
                    var tId = Thread.CurrentThread.ManagedThreadId;

                    try
                    {
                        for (var r = 0; r < 5; r++)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                string key = "key" + i;
                                object value = blob.Clone();
                                string region = "region" + r;

                                CacheItem<object> item = null;
                                if (r % 2 == 0)
                                {
                                    item = new CacheItem<object>(key, value, ExpirationMode.Sliding, TimeSpan.FromMilliseconds(10));
                                }
                                else
                                {
                                    item = new CacheItem<object>(key, value, region, ExpirationMode.Absolute, TimeSpan.FromMilliseconds(10));
                                }

                                cache.Put(item);
                                if (!cache.Add(item))
                                {
                                    cache.Put(item);
                                }

                                var result = cache.Get(key);
                                if (result == null)
                                {
                                    misses++;
                                }
                                else
                                {
                                    hits++;
                                }

                                if (!cache.Remove(key))
                                {
                                    misses++;
                                }
                                else
                                {
                                    hits++;
                                }

                                Thread.Sleep(0);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("{1} Error: {0}", ex.Message, tId);
                        throw;
                    }

                    Trace.TraceInformation("Hits: {0}, Misses: {1}", hits, misses);
                };

                ThreadTestHelper.Run(test, 2, 1);
            }
        }
开发者ID:huoxudong125,项目名称:CacheManager,代码行数:83,代码来源:ThreadRandomReadWriteTestBase.cs


注:本文中的ICacheManager.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。