标签:
1 //cache managers 2 if (config.RedisCachingEnabled) 3 { 4 builder.RegisterType<RedisCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").InstancePerLifetimeScope(); 5 } 6 else 7 { 8 builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").SingleInstance(); 9 }
2.2.RedisCachingEnabled通过读取配置文件,见Nop.Core.Configuration.NopConfig
1 var redisCachingNode = section.SelectSingleNode("RedisCaching"); 2 if (redisCachingNode != null && redisCachingNode.Attributes != null) 3 { 4 var enabledAttribute = redisCachingNode.Attributes["Enabled"]; 5 if (enabledAttribute != null) 6 config.RedisCachingEnabled = Convert.ToBoolean(enabledAttribute.Value); 7 8 var connectionStringAttribute = redisCachingNode.Attributes["ConnectionString"]; 9 if (connectionStringAttribute != null) 10 config.RedisCachingConnectionString = connectionStringAttribute.Value; 11 }
3.应用
[NonAction] protected virtual List<int> GetChildCategoryIds(int parentCategoryId) { string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_CHILD_IDENTIFIERS_MODEL_KEY, parentCategoryId, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); return _cacheManager.Get(cacheKey, () => { var categoriesIds = new List<int>(); var categories = _categoryService.GetAllCategoriesByParentCategoryId(parentCategoryId); foreach (var category in categories) { categoriesIds.Add(category.Id); categoriesIds.AddRange(GetChildCategoryIds(category.Id)); } return categoriesIds; }); }
标签:
原文地址:http://www.cnblogs.com/devilsky/p/5344381.html