Move localdb file management of PublishedSnapshotService into itself. (#15085)
* Move localdb file management of PublishedSnapshotService into itself. Added a way for the PublishedSnapshot service to clean up it's local files so (for example) Upgrade migrations have a reliable way of removing known invalid cache files without running into locking issues * Small rename to differentiate existing method from simple getter * Fix breaking change Long live default implementations 🎉 * Another breaking change fix --------- Co-authored-by: Sven Geusens <sge@umbraco.dk>
This commit is contained in:
@@ -70,6 +70,8 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
private long _mediaGen;
|
||||
private ContentStore _mediaStore = null!;
|
||||
|
||||
private string LocalFilePath => Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
|
||||
public PublishedSnapshotService(
|
||||
PublishedSnapshotServiceOptions options,
|
||||
ISyncBootStateAccessor syncBootStateAccessor,
|
||||
@@ -475,6 +477,22 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
return GetUid(_mediaStore, id);
|
||||
}
|
||||
|
||||
|
||||
public void ResetLocalDb()
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Resetting NuCache local db");
|
||||
var path = LocalFilePath;
|
||||
if (Directory.Exists(path) is false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MainDomRelease();
|
||||
Directory.Delete(path, true);
|
||||
MainDomRegister();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lazily populates the stores only when they are first requested
|
||||
/// </summary>
|
||||
@@ -603,7 +621,7 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
/// </remarks>
|
||||
private void MainDomRegister()
|
||||
{
|
||||
var path = GetLocalFilesPath();
|
||||
var path = GetAndEnsureLocalFilesPathExists();
|
||||
var localContentDbPath = Path.Combine(path, "NuCache.Content.db");
|
||||
var localMediaDbPath = Path.Combine(path, "NuCache.Media.db");
|
||||
|
||||
@@ -652,9 +670,9 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
}
|
||||
}
|
||||
|
||||
private string GetLocalFilesPath()
|
||||
private string GetAndEnsureLocalFilesPathExists()
|
||||
{
|
||||
var path = Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
var path = LocalFilePath;
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user