public static bool DeleteFromCache(string documentId) { bool result = true; try { List <string> allImbeddedDocumentsIds = new List <string>(); LoadFromCacheOptions options = new LoadFromCacheOptions() { Cache = CacheObject, DocumentId = documentId }; LEADDocument document = DocumentFactory.LoadFromCache(options); if (document != null) { allImbeddedDocumentsIds.Add(documentId); if (document.Documents != null) { foreach (var embeddedDocument in document.Documents) { allImbeddedDocumentsIds.Add(embeddedDocument.DocumentId); } } } foreach (var docId in allImbeddedDocumentsIds) { options.DocumentId = docId; DocumentFactory.DeleteFromCache(options); try { string cachedDocumentFolderPath = Path.Combine(CacheDirectory, docId); if (Directory.Exists(cachedDocumentFolderPath)) { Directory.Delete(cachedDocumentFolderPath, true); } } catch (Exception ex1) { Console.WriteLine(ex1.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); result = false; } return(result); }