Skip to content

Instantly share code, notes, and snippets.

@brunomlopes
Created December 22, 2011 16:10
Show Gist options
  • Save brunomlopes/1510830 to your computer and use it in GitHub Desktop.
Save brunomlopes/1510830 to your computer and use it in GitHub Desktop.
Telligent 6.0 plugin to auto-reset cache when a default widget file changes
#if DEBUG
public class ResetCacheOnDefaultWidgetChangePlugin : IPlugin
{
public void Initialize()
{
SetupFileSystemWatcher();
}
private void SetupFileSystemWatcher()
{
try
{
System.Diagnostics.Debug.WriteLine("ResetCacheOnDefaultWidgetChangePlugin - Setting up filesystemwatcher");
var watcher =
new FileSystemWatcher(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "filestorage",
"defaultwidgets")) {IncludeSubdirectories = true};
watcher.Changed += (sender, e) => ResetCache();
watcher.Renamed += (sender, e) => ResetCache();
watcher.Created += (sender, e) => ResetCache();
watcher.Deleted += (sender, e) => ResetCache();
watcher.EnableRaisingEvents = true;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("ResetCacheOnDefaultWidgetChangePlugin - Problem setting up filesystemwatcher : " + e);
}
}
private void ResetCache()
{
Services.Get<IFactoryDefaultScriptedContentFragmentService>().ExpireCache();
Services.Get<IScriptedContentFragmentService>().ExpireCache();
Services.Get<IContentFragmentPageService>().RemoveAllFromCache();
Services.Get<IContentFragmentService>().RefreshContentFragments();
ThemeFiles.DeleteAllHostVersionedFiles();
System.Diagnostics.Debug.Write("ResetCacheOnDefaultWidgetChangePlugin - Cache Reset");
}
public string Name
{
get { return "DEBUG: Auto-Reset Cache "; }
}
public string Description
{
get { return "Reset Telligent cache when on filesystem changes on the default widgets folder (and subfolders)"; }
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment