コード例 #1
0
        public void InvalidateEntry(IdentifierSet identifiers)
        {
            var typeIdentifiers = new List <string>();

            // Aggregate several types that appear in webhooks into one.
            if (identifiers.Type.Equals(CacheHelper.CONTENT_ITEM_TYPE_CODENAME, StringComparison.Ordinal) || identifiers.Type.Equals(CacheHelper.CONTENT_ITEM_VARIANT_TYPE_CODENAME, StringComparison.Ordinal))
            {
                typeIdentifiers.AddRange(new[] { CacheHelper.CONTENT_ITEM_TYPE_CODENAME, string.Join(string.Empty, CacheHelper.CONTENT_ITEM_TYPE_CODENAME, "_variant"), string.Join(string.Empty, CacheHelper.CONTENT_ITEM_TYPE_CODENAME, "_typed"), string.Join(string.Empty, CacheHelper.CONTENT_ITEM_TYPE_CODENAME, "_runtime_typed") });
            }
            else if (identifiers.Type.Equals(CacheHelper.CONTENT_ITEM_LISTING_IDENTIFIER, StringComparison.Ordinal))
            {
                typeIdentifiers.AddRange(new[] { string.Join(string.Empty, CacheHelper.CONTENT_ITEM_LISTING_IDENTIFIER, "_typed"), string.Join(string.Empty, CacheHelper.CONTENT_ITEM_LISTING_IDENTIFIER, "_runtime_typed") });
            }
            else
            {
                typeIdentifiers.Add(identifiers.Type);
            }

            foreach (var typeIdentifier in typeIdentifiers)
            {
                if (_memoryCache.TryGetValue(StringHelpers.Join("dummy", typeIdentifier, identifiers.Codename), out CancellationTokenSource dummyEntry))
                {
                    // Mark all subscribers to the CancellationTokenSource as invalid.
                    dummyEntry.Cancel();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Looks up the cache for an entry and passes it to a method that extracts specific dependencies.
        /// </summary>
        /// <typeparam name="T">Type of the cache entry.</typeparam>
        /// <param name="identifierSet">Identifiers used to look up the cache for the entry.</param>
        /// <param name="dependencyListFactory">The method that takes the entry, and uses them to extract dependencies from it.</param>
        /// <returns>Identifiers of the dependencies.</returns>
        public IEnumerable <IdentifierSet> GetDependenciesByName <T>(IdentifierSet identifierSet, Func <T, IEnumerable <IdentifierSet> > dependencyFactory)
            where T : class
        {
            var dependencies = new List <IdentifierSet>();

            if (TryGetValue(new[] { identifierSet.Type, identifierSet.Codename }, out T cacheEntry))
            {
                return(dependencyFactory(cacheEntry));
            }

            return(dependencies);
        }
コード例 #3
0
        public void RaiseWebhookNotification(object sender, string operation, IdentifierSet identifierSet)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (string.IsNullOrEmpty(operation))
            {
                throw new ArgumentException("The 'operation' parameter must be a non-empty string.", nameof(operation));
            }

            if (identifierSet == null)
            {
                throw new ArgumentNullException(nameof(identifierSet));
            }

            WebhookNotification(sender, new WebhookNotificationEventArgs(identifierSet, operation));
        }
コード例 #4
0
        /// <summary>
        /// Invalidates (clears) a cache entry.
        /// </summary>
        /// <param name="identifiers">Identifiers of the entry.</param>
        public void InvalidateEntry(IdentifierSet identifiers)
        {
            if (_dependentTypesResolver == null)
            {
                throw new ArgumentNullException(nameof(_dependentTypesResolver));
            }

            if (identifiers == null)
            {
                throw new ArgumentNullException(nameof(identifiers));
            }

            foreach (var typeIdentifier in _dependentTypesResolver.GetDependentTypeNames(identifiers.Type))
            {
                if (MemoryCache.TryGetValue(StringHelpers.Join(KenticoCloudCacheHelper.DUMMY_IDENTIFIER, typeIdentifier, identifiers.Codename), out CancellationTokenSource dummyEntry))
                {
                    // Mark all subscribers to the CancellationTokenSource as invalid.
                    dummyEntry.Cancel();
                }
            }
        }
        public void RaiseWebhookNotificationThrows(bool createSender, bool createIdentifierSet)
        {
            object        sender        = null;
            IdentifierSet identifierSet = null;

            if (createSender)
            {
                sender = new object();
            }

            if (createIdentifierSet)
            {
                identifierSet = new IdentifierSet
                {
                    Codename = "Test",
                    Type     = "Test"
                };
            }

            var listener = new WebhookListener();

            Assert.Throws <ArgumentNullException>(() => listener.RaiseWebhookNotification(sender, "upsert", identifierSet));
        }