【发布时间】:2020-09-08 01:00:18
【问题描述】:
我有一个 Asp.Net Core 3.1 Razor Pages 网站,其中有一个静态的 Repository 类,其中包含最常用的项目。我经常搜索这些项目,初始化它们大约需要 4 分钟。
public static class Repository
{
public static Dictionary<int, RepositoryPerson> People { get; private set; }
public static async Task InitAsync(INoSqlSettings settings)
{
if (People != null || loading)
{
return;
}
loading = true;
var people = await db.People.ToDictionaryAsync(p => p.Id);
People = ConvertToRepository(people);
//..and lots of other stuff
loading = false;
}
}
起初,我尝试使用托管服务加载它,但由于耗时太长而失败。现在我将它加载到Index.cshtml.cs 文件的OnGetAsync() 中。但问题是每隔一段时间,似乎 .exe 文件会因为网站再次初始化而关闭。这是正常的吗?如何让程序只运行一次并永久共享内存存储库?
【问题讨论】:
-
是的,托管在 IIS 中的 Web 应用程序通常会回收。见Why do IIS application pools need to be recycled?
标签: asp.net asp.net-core razor-pages