public PublishedMemberCache(XmlStore xmlStore, ICacheProvider requestCacheProvider, IMemberService memberService, PublishedContentTypeCache contentTypeCache) { _requestCache = requestCacheProvider; _memberService = memberService; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; }
// initialize a PublishedContentCache instance with // an XmlStore containing the master xml // an IAppCache that should be at request-level // a RoutesCache - need to cleanup that one // a preview token string (or null if not previewing) public PublishedContentCache( XmlStore xmlStore, // an XmlStore containing the master xml IDomainCache domainCache, // an IDomainCache implementation IAppCache appCache, // an IAppCache that should be at request-level IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor, PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache RoutesCache routesCache, // a RoutesCache string previewToken) // a preview token string (or null if not previewing) : base(previewToken.IsNullOrWhiteSpace() == false) { _appCache = appCache; _globalSettings = globalSettings; _umbracoContextAccessor = umbracoContextAccessor; _routesCache = routesCache; // may be null for unit-testing _contentTypeCache = contentTypeCache; _domainCache = domainCache; _domainHelper = new DomainHelper(_domainCache, siteDomainHelper); _xmlStore = xmlStore; _xml = _xmlStore.Xml; // capture - because the cache has to remain consistent if (previewToken.IsNullOrWhiteSpace() == false) { _previewContent = new PreviewContent(_xmlStore, previewToken); } }
private PublishedSnapshotService(ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IScopeProvider scopeProvider, ICacheProvider requestCache, IEnumerable <IUrlSegmentProvider> segmentProviders, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, PublishedContentTypeCache contentTypeCache, MainDom mainDom, bool testing, bool enableRepositoryEvents) : base(publishedSnapshotAccessor, variationContextAccessor) { _routesCache = new RoutesCache(); _publishedContentTypeFactory = publishedContentTypeFactory; _contentTypeCache = contentTypeCache ?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, logger); _xmlStore = new XmlStore(serviceContext, scopeProvider, _routesCache, _contentTypeCache, segmentProviders, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents, documentRepository, mediaRepository, memberRepository, globalSettings); _domainService = serviceContext.DomainService; _memberService = serviceContext.MemberService; _mediaService = serviceContext.MediaService; _userService = serviceContext.UserService; _defaultCultureAccessor = defaultCultureAccessor; _requestCache = requestCache; _globalSettings = globalSettings; _siteDomainHelper = siteDomainHelper; }
private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, ICacheProvider cacheProvider, PublishedContentTypeCache contentTypeCache) { _xmlNode = xmlNode; _isPreviewing = isPreviewing; _cacheProvider = cacheProvider; _contentTypeCache = contentTypeCache; }
public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor) { _requestCache = requestCache; _memberService = memberService; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; _umbracoContextAccessor = umbracoContextAccessor; }
/// <summary> /// Generally used for unit testing to use an explicit examine searcher /// </summary> /// <param name="mediaService"></param> /// <param name="userService"></param> /// <param name="searchProvider"></param> /// <param name="indexProvider"></param> /// <param name="cacheProvider"></param> /// <param name="contentTypeCache"></param> internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, BaseIndexProvider indexProvider, ICacheProvider cacheProvider, PublishedContentTypeCache contentTypeCache) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _searchProvider = searchProvider ?? throw new ArgumentNullException(nameof(searchProvider)); _indexProvider = indexProvider ?? throw new ArgumentNullException(nameof(indexProvider)); _cacheProvider = cacheProvider; _contentTypeCache = contentTypeCache; }
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, ICacheProvider cacheProvider, PublishedContentTypeCache contentTypeCache) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _cacheProvider = cacheProvider; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; }
public MemberCache(bool previewDefault, ICacheProvider snapshotCache, IMemberService memberService, IDataTypeService dataTypeService, ILocalizationService localizationService, PublishedContentTypeCache contentTypeCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor) { _snapshotCache = snapshotCache; _publishedSnapshotAccessor = publishedSnapshotAccessor; VariationContextAccessor = variationContextAccessor; _memberService = memberService; _dataTypeService = dataTypeService; _localizationService = localizationService; _previewDefault = previewDefault; _contentTypeCache = contentTypeCache; }
/// <summary> /// Generally used for unit testing to use an explicit examine searcher /// </summary> /// <param name="mediaService"></param> /// <param name="userService"></param> /// <param name="searchProvider"></param> /// <param name="appCache"></param> /// <param name="contentTypeCache"></param> /// <param name="entitySerializer"></param> internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer, IUmbracoContextAccessor umbracoContextAccessor) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _searchProvider = searchProvider ?? throw new ArgumentNullException(nameof(searchProvider)); _appCache = appCache; _contentTypeCache = contentTypeCache; _entitySerializer = entitySerializer; _umbracoContextAccessor = umbracoContextAccessor; }
public MemberCache(bool previewDefault, IAppCache snapshotCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IEntityXmlSerializer entitySerializer) { _snapshotCache = snapshotCache; _publishedSnapshotAccessor = publishedSnapshotAccessor; VariationContextAccessor = variationContextAccessor; _entitySerializer = entitySerializer; _memberService = memberService; _previewDefault = previewDefault; _contentTypeCache = contentTypeCache; }
private XmlPublishedContent( XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache) { _xmlNode = xmlNode; _isPreviewing = isPreviewing; _appCache = appCache; _contentTypeCache = contentTypeCache; }
public MemberCache( bool previewDefault, PublishedContentTypeCache contentTypeCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) { _publishedSnapshotAccessor = publishedSnapshotAccessor; _variationContextAccessor = variationContextAccessor; _publishedModelFactory = publishedModelFactory; _previewDefault = previewDefault; _contentTypeCache = contentTypeCache; }
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer, IUmbracoContextAccessor umbracoContextAccessor) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _appCache = appCache; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; _entitySerializer = entitySerializer; _umbracoContextAccessor = umbracoContextAccessor; }
private XmlPublishedContent( XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IVariationContextAccessor variationContextAccessor) : base(variationContextAccessor) { _xmlNode = xmlNode; _isPreviewing = isPreviewing; _appCache = appCache; _contentTypeCache = contentTypeCache; _variationContextAccessor = variationContextAccessor; }
private XmlPublishedContent( XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor) : base(umbracoContextAccessor) { _xmlNode = xmlNode; _isPreviewing = isPreviewing; _appCache = appCache; _contentTypeCache = contentTypeCache; _umbracoContextAccessor = umbracoContextAccessor; }
/// <summary> /// Gets an IPublishedContent corresponding to an Xml cache node. /// </summary> /// <param name="node">The Xml node.</param> /// <param name="isPreviewing">A value indicating whether we are previewing or not.</param> /// <param name="appCache">A cache.</param> /// <param name="contentTypeCache">A content type cache.</param> /// <param name="umbracoContextAccessor">A umbraco context accessor</param> /// <returns>The IPublishedContent corresponding to the Xml cache node.</returns> /// <remarks>Maintains a per-request cache of IPublishedContent items in order to make /// sure that we create only one instance of each for the duration of a request. The /// returned IPublishedContent is a model, if models are enabled.</remarks> public static IPublishedContent Get(XmlNode node, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache) { // only 1 per request var attrs = node.Attributes; var id = attrs?.GetNamedItem("id").Value; if (id.IsNullOrWhiteSpace()) { throw new InvalidOperationException("Node has no ID attribute."); } var key = CacheKeyPrefix + id; // dont bother with preview, wont change during request in Xml cache return((IPublishedContent)appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache)).CreateModel())); }
// used in some tests internal XmlPublishedSnapshotService( ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IScopeProvider scopeProvider, IAppCache requestCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, ILoggerFactory loggerFactory, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IShortStringHelper shortStringHelper, IEntityXmlSerializer entitySerializer, PublishedContentTypeCache contentTypeCache, MainDom mainDom, bool testing, bool enableRepositoryEvents) { _routesCache = new RoutesCache(); _publishedContentTypeFactory = publishedContentTypeFactory; _contentTypeCache = contentTypeCache ?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, loggerFactory.CreateLogger <PublishedContentTypeCache>()); _xmlStore = new XmlStore(serviceContext.ContentTypeService, serviceContext.ContentService, scopeProvider, _routesCache, _contentTypeCache, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents, documentRepository, mediaRepository, memberRepository, entitySerializer, hostingEnvironment, hostingLifetime, shortStringHelper); _domainService = serviceContext.DomainService; _mediaService = serviceContext.MediaService; _userService = serviceContext.UserService; _defaultCultureAccessor = defaultCultureAccessor; _variationContextAccessor = variationContextAccessor; _requestCache = requestCache; _umbracoContextAccessor = umbracoContextAccessor; _globalSettings = globalSettings; _entitySerializer = entitySerializer; }
// used in some tests internal PublishedSnapshotService(ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IScopeProvider scopeProvider, ICacheProvider requestCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, PublishedContentTypeCache contentTypeCache, MainDom mainDom, bool testing, bool enableRepositoryEvents) : this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache, Enumerable.Empty <IUrlSegmentProvider>(), publishedSnapshotAccessor, variationContextAccessor, documentRepository, mediaRepository, memberRepository, defaultCultureAccessor, logger, globalSettings, siteDomainHelper, contentTypeCache, mainDom, testing, enableRepositoryEvents) { }
protected virtual IPublishedSnapshotService CreatePublishedSnapshotService() { var cache = NoAppCache.Instance; ContentTypesCache = new PublishedContentTypeCache( Factory.GetInstance <IContentTypeService>(), Factory.GetInstance <IMediaTypeService>(), Factory.GetInstance <IMemberTypeService>(), Factory.GetInstance <IPublishedContentTypeFactory>(), Logger); // testing=true so XmlStore will not use the file nor the database var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor); var variationContextAccessor = new TestVariationContextAccessor(); var service = new XmlPublishedSnapshotService( ServiceContext, Factory.GetInstance <IPublishedContentTypeFactory>(), ScopeProvider, cache, publishedSnapshotAccessor, variationContextAccessor, Factory.GetInstance <IUmbracoContextAccessor>(), Factory.GetInstance <IDocumentRepository>(), Factory.GetInstance <IMediaRepository>(), Factory.GetInstance <IMemberRepository>(), DefaultCultureAccessor, Logger, Factory.GetInstance <IGlobalSettings>(), new SiteDomainHelper(), Factory.GetInstance <IEntityXmlSerializer>(), ContentTypesCache, null, true, Options.PublishedRepositoryEvents); // initialize PublishedCacheService content with an Xml source service.XmlStore.GetXmlDocument = () => { var doc = new XmlDocument(); doc.LoadXml(GetXmlContent(0)); return(doc); }; return(service); }
public PublishedMemberCache(PublishedContentTypeCache contentTypeCache, IVariationContextAccessor variationContextAccessor) { _contentTypeCache = contentTypeCache; _variationContextAccessor = variationContextAccessor; }
public DictionaryPublishedContent( IReadOnlyDictionary <string, string> valueDictionary, Func <int, IPublishedContent> getParent, Func <int, XPathNavigator, IEnumerable <IPublishedContent> > getChildren, Func <DictionaryPublishedContent, string, IPublishedProperty> getProperty, IAppCache appCache, IVariationContextAccessor variationContextAccessor, PublishedContentTypeCache contentTypeCache, XPathNavigator nav, bool fromExamine) : base(variationContextAccessor) { if (valueDictionary == null) { throw new ArgumentNullException(nameof(valueDictionary)); } if (getParent == null) { throw new ArgumentNullException(nameof(getParent)); } if (getProperty == null) { throw new ArgumentNullException(nameof(getProperty)); } _getParent = new Lazy <IPublishedContent>(() => getParent(ParentId)); _getChildren = new Lazy <IEnumerable <IPublishedContent> >(() => getChildren(Id, nav)); _getProperty = getProperty; _appCache = appCache; LoadedFromExamine = fromExamine; ValidateAndSetProperty(valueDictionary, val => _id = Int32.Parse(val), "id", "nodeId", "__NodeId"); //should validate the int! ValidateAndSetProperty(valueDictionary, val => _key = Guid.Parse(val), "key", "__key", "__Key"); //ValidateAndSetProperty(valueDictionary, val => _templateId = int.Parse(val), "template", "templateId"); ValidateAndSetProperty(valueDictionary, val => _sortOrder = Int32.Parse(val), "sortOrder"); ValidateAndSetProperty(valueDictionary, val => _name = val, "nodeName"); ValidateAndSetProperty(valueDictionary, val => _urlName = val, "urlName"); ValidateAndSetProperty(valueDictionary, val => _documentTypeAlias = val, "nodeTypeAlias", ExamineFieldNames.ItemTypeFieldName); ValidateAndSetProperty(valueDictionary, val => _documentTypeId = Int32.Parse(val), "nodeType"); //ValidateAndSetProperty(valueDictionary, val => _writerId = int.Parse(val), "writerID"); ValidateAndSetProperty(valueDictionary, val => _creatorId = Int32.Parse(val), "creatorID", "writerID"); //this is a bit of a hack fix for: U4-1132 ValidateAndSetProperty(valueDictionary, val => _path = val, "path", "__Path"); ValidateAndSetProperty(valueDictionary, val => _createDate = ParseDateTimeValue(val), "createDate"); ValidateAndSetProperty(valueDictionary, val => _updateDate = ParseDateTimeValue(val), "updateDate"); ValidateAndSetProperty(valueDictionary, val => _level = Int32.Parse(val), "level"); ValidateAndSetProperty(valueDictionary, val => { int pId; ParentId = -1; if (Int32.TryParse(val, out pId)) { ParentId = pId; } }, "parentID"); _contentType = contentTypeCache.Get(PublishedItemType.Media, _documentTypeAlias); _properties = new Collection <IPublishedProperty>(); //handle content type properties //make sure we create them even if there's no value foreach (var propertyType in _contentType.PropertyTypes) { var alias = propertyType.Alias; _keysAdded.Add(alias); string value; const bool isPreviewing = false; // false :: never preview a media var property = valueDictionary.TryGetValue(alias, out value) == false || value == null ? new XmlPublishedProperty(propertyType, this, isPreviewing) : new XmlPublishedProperty(propertyType, this, isPreviewing, value); _properties.Add(property); } //loop through remaining values that haven't been applied foreach (var i in valueDictionary.Where(x => _keysAdded.Contains(x.Key) == false && // not already processed IgnoredKeys.Contains(x.Key) == false)) // not ignorable { if (i.Key.InvariantStartsWith("__")) { // no type for that one, dunno how to convert, drop it //IPublishedProperty property = new PropertyResult(i.Key, i.Value, PropertyResultType.CustomProperty); //_properties.Add(property); } else { // this is a property that does not correspond to anything, ignore and log Current.Logger.LogWarning("Dropping property '{PropertyKey}' because it does not belong to the content type.", i.Key); } } }
// gets a new set of elements // always creates a new set of elements, // even though the underlying elements may not change (store snapshots) public PublishedSnapshot.PublishedSnapshotElements GetElements(bool previewDefault) { EnsureCaches(); // note: using ObjectCacheAppCache for elements and snapshot caches // is not recommended because it creates an inner MemoryCache which is a heavy // thing - better use a dictionary-based cache which "just" creates a concurrent // dictionary // for snapshot cache, DictionaryAppCache MAY be OK but it is not thread-safe, // nothing like that... // for elements cache, DictionaryAppCache is a No-No, use something better. // ie FastDictionaryAppCache (thread safe and all) ContentStore.Snapshot contentSnap, mediaSnap; SnapDictionary <int, Domain> .Snapshot domainSnap; IAppCache elementsCache; // Here we are reading/writing to shared objects so we need to lock (can't be _storesLock which manages the actual nucache files // and would result in a deadlock). Even though we are locking around underlying readlocks (within CreateSnapshot) it's because // we need to ensure that the result of contentSnap.Gen (etc) and the re-assignment of these values and _elements cache // are done atomically. lock (_elementsLock) { IScopeContext scopeContext = _scopeProvider.Context; if (scopeContext == null) { contentSnap = _contentStore.CreateSnapshot(); mediaSnap = _mediaStore.CreateSnapshot(); domainSnap = _domainStore.CreateSnapshot(); elementsCache = _elementsCache; } else { contentSnap = _contentStore.LiveSnapshot; mediaSnap = _mediaStore.LiveSnapshot; domainSnap = _domainStore.Test.LiveSnapshot; elementsCache = _elementsCache; // this is tricky // we are returning elements composed from live snapshots, which we need to replace // with actual snapshots when the context is gone - but when the action runs, there // still is a context - so we cannot get elements - just resync = nulls the current // elements // just need to make sure nothing gets elements in another enlisted action... so using // a MaxValue to make sure this one runs last, and it should be ok scopeContext.Enlist("Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Resync", () => this, (completed, svc) => { svc.CurrentPublishedSnapshot?.Resync(); }, int.MaxValue); } // create a new snapshot cache if snapshots are different gens if (contentSnap.Gen != _contentGen || mediaSnap.Gen != _mediaGen || domainSnap.Gen != _domainGen || _elementsCache == null) { _contentGen = contentSnap.Gen; _mediaGen = mediaSnap.Gen; _domainGen = domainSnap.Gen; elementsCache = _elementsCache = new FastDictionaryAppCache(); } } var snapshotCache = new DictionaryAppCache(); var memberTypeCache = new PublishedContentTypeCache(null, null, _serviceContext.MemberTypeService, _publishedContentTypeFactory, _loggerFactory.CreateLogger <PublishedContentTypeCache>()); var defaultCulture = _defaultCultureAccessor.DefaultCulture; var domainCache = new DomainCache(domainSnap, defaultCulture); return(new PublishedSnapshot.PublishedSnapshotElements { ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, Options.Create(_globalSettings), _variationContextAccessor), MediaCache = new MediaCache(previewDefault, mediaSnap, _variationContextAccessor), MemberCache = new MemberCache(previewDefault, memberTypeCache, _publishedSnapshotAccessor, _variationContextAccessor, _publishedModelFactory), DomainCache = domainCache, SnapshotCache = snapshotCache, ElementsCache = elementsCache }); }