2020-12-21 17:41:12 +11:00
|
|
|
using System;
|
2020-05-27 14:14:32 +02:00
|
|
|
using System.Reflection.Metadata;
|
2020-12-21 17:41:12 +11:00
|
|
|
using System.Threading.Tasks;
|
2020-05-27 14:14:32 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Umbraco.Core;
|
2020-02-04 19:18:35 +01:00
|
|
|
using Umbraco.Web.Cache;
|
2020-05-27 14:14:32 +02:00
|
|
|
using Umbraco.Web.Common.Attributes;
|
2020-02-04 19:18:35 +01:00
|
|
|
using Umbraco.Web.PublishedCache;
|
|
|
|
|
|
2020-05-27 14:14:32 +02:00
|
|
|
namespace Umbraco.Web.BackOffice.Controllers
|
2020-02-04 19:18:35 +01:00
|
|
|
{
|
2020-12-21 17:41:12 +11:00
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
2020-02-04 19:18:35 +01:00
|
|
|
public class PublishedSnapshotCacheStatusController : UmbracoAuthorizedApiController
|
|
|
|
|
{
|
|
|
|
|
private readonly IPublishedSnapshotService _publishedSnapshotService;
|
2020-12-21 17:41:12 +11:00
|
|
|
private readonly IPublishedSnapshotStatus _publishedSnapshotStatus;
|
2020-05-27 14:14:32 +02:00
|
|
|
private readonly DistributedCache _distributedCache;
|
2020-02-04 19:18:35 +01:00
|
|
|
|
2020-12-21 17:41:12 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="PublishedSnapshotCacheStatusController"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PublishedSnapshotCacheStatusController(
|
|
|
|
|
IPublishedSnapshotService publishedSnapshotService,
|
|
|
|
|
IPublishedSnapshotStatus publishedSnapshotStatus,
|
|
|
|
|
DistributedCache distributedCache)
|
2020-02-04 19:18:35 +01:00
|
|
|
{
|
|
|
|
|
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
|
2020-12-21 17:41:12 +11:00
|
|
|
_publishedSnapshotStatus = publishedSnapshotStatus;
|
2020-05-27 14:14:32 +02:00
|
|
|
_distributedCache = distributedCache;
|
2020-02-04 19:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:41:12 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Rebuilds the Database cache
|
|
|
|
|
/// </summary>
|
2020-02-04 19:18:35 +01:00
|
|
|
[HttpPost]
|
|
|
|
|
public string RebuildDbCache()
|
|
|
|
|
{
|
|
|
|
|
_publishedSnapshotService.Rebuild();
|
2020-12-21 17:41:12 +11:00
|
|
|
return _publishedSnapshotStatus.GetStatus();
|
2020-02-04 19:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:41:12 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a status report
|
|
|
|
|
/// </summary>
|
2020-02-04 19:18:35 +01:00
|
|
|
[HttpGet]
|
2020-12-21 17:41:12 +11:00
|
|
|
public string GetStatus() => _publishedSnapshotStatus.GetStatus();
|
2020-02-04 19:18:35 +01:00
|
|
|
|
2020-12-21 17:41:12 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Cleans up unused snapshots
|
|
|
|
|
/// </summary>
|
2020-02-04 19:18:35 +01:00
|
|
|
[HttpGet]
|
2020-12-21 17:41:12 +11:00
|
|
|
public async Task<string> Collect()
|
2020-02-04 19:18:35 +01:00
|
|
|
{
|
|
|
|
|
GC.Collect();
|
2020-12-21 17:41:12 +11:00
|
|
|
await _publishedSnapshotService.CollectAsync();
|
|
|
|
|
return _publishedSnapshotStatus.GetStatus();
|
2020-02-04 19:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2020-12-21 17:41:12 +11:00
|
|
|
public void ReloadCache() => _distributedCache.RefreshAllPublishedSnapshot();
|
2020-02-04 19:18:35 +01:00
|
|
|
}
|
|
|
|
|
}
|