-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emptying Combinator cache on shell activation if marker file exists; …
…Adding validate-pull-request.yml to csproj
- Loading branch information
1 parent
b0d6c52
commit 37e25f3
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Piedone.Combinator.Constants | ||
{ | ||
public static class FileNames | ||
{ | ||
public const string ClearCache = "_" + nameof(ClearCache); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Piedone.Combinator.Constants | ||
{ | ||
public static class FolderNames | ||
{ | ||
public const string PiedoneModules = "_" + nameof(PiedoneModules); | ||
public const string Combinator = nameof(Combinator); | ||
public const string Sites = nameof(Sites); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Orchard.Environment; | ||
using Orchard.Environment.Configuration; | ||
using Orchard.Environment.Extensions; | ||
using Orchard.FileSystems.AppData; | ||
using Piedone.Combinator.Constants; | ||
using Piedone.Combinator.Services; | ||
|
||
namespace Piedone.Combinator.EventHandlers | ||
{ | ||
[OrchardFeature("Piedone.Combinator")] | ||
public class CacheFileEventHandler : IOrchardShellEvents | ||
{ | ||
private const string ClearCacheFileName = FileNames.ClearCache + ".txt"; | ||
|
||
private readonly ICacheFileService _cacheFileService; | ||
private readonly IAppDataFolder _appDataFolder; | ||
|
||
private readonly string _basePath; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether emptying Combinator cache is disabled, primarily through HostComponents.config. | ||
/// </summary> | ||
public bool IsEmptyingCacheDisabled { get; set; } | ||
|
||
public CacheFileEventHandler(ICacheFileService cacheFileService, IAppDataFolder appDataFolder, ShellSettings shellSettings) | ||
{ | ||
_cacheFileService = cacheFileService; | ||
_appDataFolder = appDataFolder; | ||
|
||
_basePath = _appDataFolder.Combine(FolderNames.Sites, shellSettings.Name, FolderNames.PiedoneModules, FolderNames.Combinator); | ||
} | ||
|
||
public void Activated() | ||
{ | ||
if (IsEmptyingCacheDisabled) return; | ||
|
||
var pathToClearCacheFile = _appDataFolder.Combine(_basePath, ClearCacheFileName); | ||
|
||
if (!_appDataFolder.FileExists(pathToClearCacheFile)) return; | ||
|
||
_cacheFileService.Empty(); | ||
|
||
_appDataFolder.DeleteFile(pathToClearCacheFile); | ||
} | ||
|
||
public void Terminating() | ||
{ | ||
// Terminating event does not need to be implemented. | ||
} | ||
} | ||
} |
This file contains 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