Exemplo n.º 1
0
        public static void DeleteDocument(string documentId, bool preventIfPreCached, bool throwIfNull)
        {
            var cache = ServiceHelper.Cache;

            using (var document = DocumentFactory.LoadFromCache(cache, documentId))
            {
                if (throwIfNull)
                {
                    DocumentHelper.CheckLoadFromCache(document);
                }

                if (document != null)
                {
                    // Check if it's one of our pre-cached documents.
                    // If it is, don't remove it from the cache.
                    if (PreCacheHelper.PreCacheExists && document.Uri != null)
                    {
                        if (preventIfPreCached && PreCacheHelper.CheckDocument(document.Uri, document.Images.MaximumImagePixelSize) != null)
                        {
                            return;
                        }
                        else
                        {
                            PreCacheHelper.RemoveDocument(document.Uri, new int[] { document.Images.MaximumImagePixelSize });
                        }
                    }

                    document.AutoDeleteFromCache = true;
                    // But not the children documents (if any)
                    foreach (var child in document.Documents)
                    {
                        child.AutoDeleteFromCache = false;
                    }
                    document.AutoDisposeDocuments = true;
                }
            }
        }