private FieldList GetFieldListForCategory(CategorySitecoreItem item, VersionUri version) { var fields = Cache.Lookup(item.Id, version); if (fields != null) { if (UseVerboseLogging) { _log.Log <ContentNodeDataProvider>("cache hit"); } Stats.Hit(); return(fields); } if (UseVerboseLogging) { _log.Log <ContentNodeDataProvider>("cache hit"); } Stats.Miss(); PopulateCacheWithFieldListsForAllVersions(item); fields = _cache.Lookup(item.Id, version); if (fields != null) { return(fields); } return(item.GetFieldList(version)); }
private void PopulateCacheWithChildrensFieldLists(CategorySitecoreItem categoryItem) { if (categoryItem == null) { return; } if (AreAllChildrenPresent(categoryItem)) { return; } int categoryId = int.Parse(categoryItem.Node.ItemId); var repository = ObjectFactory.Instance.Resolve <IRepository <Category> >(); var categories = repository.Select(new ChildCategoryQuery(categoryId)).ToList(); foreach (var category in categories) { if (!_sitecoreItems.ContainsKey(new ID(category.Guid))) { continue; } // Skip, if category does not exist anymore. This can happen, if the category is orphaned, in the database. var childItem = _sitecoreItems[new ID(category.Guid)] as ContentNodeSitecoreItem; if (childItem == null) { continue; } foreach (VersionUri version in GetItemVersions()) { var list = new FieldList(); list.SafeAdd(FieldIDs.Icon, childItem.GetIcon()); list.SafeAdd(FieldIDs.Sortorder, childItem.Node.SortOrder.ToString()); list.SafeAdd(FieldIDs.DisplayName, childItem.Node.Name); _categoryValueProvider.AddDataFromCategory(list, version, category); //_log.Log<ContentNodeDataProvider>(string.Format("Storing: {0}", category.Guid)); Cache.Store(new ID(category.Guid), version, list); } } }
private void PopulateCacheWithFieldListsForAllVersions(CategorySitecoreItem item) { var repository = ObjectFactory.Instance.Resolve <IRepository <Category> >(); var category = repository.Select(new SingleCategoryQuery(int.Parse(item.Node.ItemId))).FirstOrDefault(); if (category == null) { throw new Exception("Could not read category with id " + item.Node.ItemId); } foreach (VersionUri version in GetItemVersions()) { var list = new FieldList(); list.SafeAdd(FieldIDs.Icon, item.GetIcon()); list.SafeAdd(FieldIDs.Sortorder, item.Node.SortOrder.ToString()); list.SafeAdd(FieldIDs.DisplayName, item.Node.Name); _categoryValueProvider.AddDataFromCategory(list, version, category); //_log.Log<ContentNodeDataProvider>(string.Format("Storing: {0}", item.Id)); Cache.Store(item.Id, version, list); } }