/// <summary> /// Adds the url to the local cache, to avoid duplicating requests. /// </summary> /// <param name="item">The item.</param> private bool AddToLocalCache(Item item) { var url = VarnishCache.GetRelativeItemUrl(item); var finalUrl = VarnishSettings.Url + url; var cachedUrl = String.IsNullOrEmpty(VarnishSettings.Host) ? finalUrl : "http://" + VarnishSettings.Host + url; if (_purgedUrls.Contains(cachedUrl)) { return(false); } _purgedUrls.Add(cachedUrl); return(true); }
/// <summary> /// Purges the item. /// </summary> /// <param name="item">The item.</param> /// <param name="publishRelatedItems">if set to <c>true</c> also tries to purge the related items.</param> private void PurgeItem(Item item, bool publishRelatedItems) { if ((item.Paths.IsMediaItem && !item.HasChildren) || item.Paths.IsContentItem) { if (AddToLocalCache(item)) { VarnishCache.Clear(item); } } if (!publishRelatedItems) { return; } var referenced = GetReferences(item); foreach (var relatedItem in referenced.Where(relatedItem => (relatedItem.Paths.IsMediaItem && !relatedItem.HasChildren) || relatedItem.Paths.IsContentItem).Where(AddToLocalCache)) { VarnishCache.Clear(relatedItem); } }