Created
December 22, 2011 16:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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