using CloudGaming.Code.Config;
using CloudGaming.ExtApi.Base;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using System.Text;

namespace CloudGaming.ExtApi.Controllers
{

    /// <summary>
    /// 缓存管理
    /// </summary>
    public class CacheController : CloudGamingControllerBase
    {
        public CacheController(IServiceProvider _serviceProvider) : base(_serviceProvider)
        {
        }

        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ClearAllCacheData()
        {
            var outputStream = Response.Body;

            Response.ContentType = "text/plain"; // 设置响应内容类型
            Response.StatusCode = 200; // 设置状态码
            await foreach (var item in new AppConfigBLL(ServiceProvider).ClearAllCacheData())
            {
                if (item == null)
                {
                    continue;
                }
                await outputStream.WriteAsync(Encoding.UTF8.GetBytes(item));
                await outputStream.FlushAsync();
            }
            return new EmptyResult();
        }
    }
}
