I have a site collection scoped feature that should provision a css file to the "Style Library" of a site collection. The feature also performs cleanup of the file in the deactivation receiver.
I have experienced some problem with the blob cache of the web application storing the old file when I update it (deploy solution, reactivate feature etc). The file in the library is the correct one (proved by downloading it), but IE/Chrome/Firefox/Whatever receive the old version of the file.
Discovering after some lost hours the magic world of the blob cache, I have resort to a simple script like this:
$webApp = Get-SPWebApplication "<WebApplicationURL>"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Write-Host "Flushed the BLOB cache for:" $webApp
to flush the cache for the web application. No need to say, it magically start working again as expected.
So, to avoid this problem in the future, I was thinking to add a feature activated receiver to my code, and in it call the FlushBlobCache method.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite parentSite = ((SPSite)properties.Feature.Parent);
Microsoft.SharePoint.Publishing.PublishingCache.FlushBlobCache(parentSite.WebApplication);
}
Tested that, I receive an AcessViolationError.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.SharePoint.Publishing.PublishingCache.FlushBlobCache(SPWebApplication webapplication)
Anyone know if what I am attempting to do is even possibile? Is that an effect of the dared sp2010 "RemoteAdministratorAccessDenied" security setting? Do I need to impersonate a specific user (was using the farm account, so I don't belive that's the problem - may give RunWithElevated a try) or it is simply impossible to do in a site collection feature?
UPDATE: Seems that all is caused by a nice snipet of code similar to this (reflector taken)
if (!webapp.Farm.CurrentUserIsAdministrator())
{
throw new AccessViolationException();
}
So I suppose that this explain the error (won't ACCESS DENIED be a more accurate ex to throw????). So the new question is: has anyone tried this before and found an acceptable way to perform this operation?