/// <summary> /// Flushes the BLOB cache for the specified Web Application. /// WARNING: This method needs to be run as Farm Admin and have security_admin SQL server role and the db_owner role /// on the web app's content DB in order to successfully flush the web app's BLOB cache. /// </summary> /// <param name="webApplication">The SharePoint web application.</param> public void FlushBlobCache(SPWebApplication webApplication) { try { PublishingCache.FlushBlobCache(webApplication); } catch (SPException exception) { this.logger.Error("Failed to flush the BLOB cache accross the web app. You need You need security_admin SQL server role and the db_owner role on the web app's content DB. Caught and swallowed exception: {0}", exception); } catch (AccessViolationException exception) { this.logger.Warn("Received an AccessViolationException when flushing BLOB Cache. Trying again with RemoteAdministratorAccessDenied set to true. Caught and swallowed exception: {0}", exception); bool initialRemoteAdministratorAccessDenied = true; SPWebService myService = SPWebService.ContentService; try { initialRemoteAdministratorAccessDenied = myService.RemoteAdministratorAccessDenied; myService.RemoteAdministratorAccessDenied = false; myService.Update(); PublishingCache.FlushBlobCache(webApplication); } finally { myService.RemoteAdministratorAccessDenied = initialRemoteAdministratorAccessDenied; myService.Update(); } } }
public void FlushBlobCache(SPWebApplicationInstance webApplication) { if (webApplication == null) { throw new JavaScriptException(this.Engine, "Error", "An instance of a Web Application object must be specified as the first argument."); } PublishingCache.FlushBlobCache(webApplication.SPWebApplication); }