Asp.net核心,缓存Taghelper和IMemoryCache有什么区别?

Asp.net core, what is difference between cache Taghelper and IMemoryCache?

我正在 Asp.net core 2.1 项目上工作。在我的项目中,有一个菜单绑定了 2 tables GroupsubGroup.

Group Table 包含 IdGroupNamesubGroup table 包含 Id,groupIdsubGroupName.

现在要提高我想要使用缓存的网站的加载速度。

1 - cache 从数据库获取数据的最佳方式是什么。

2 - <cache></cache>(用于 view)和 IMemoryCache(用于 controllerclass) 在 asp.net 核心?

如果您只想缓存服务器端的查询结果,您可以使用 IMemoryCache,或者您可以使用 Cache TagHelper 来缓存视图的特定部分,该部分可能包含也可能不包含那说查询。

还可以使用 IMemoryCache 进行全局设置,而使用 Cache TagHelper 则必须为每次使用标签手动进行设置。

有趣的事实:其核心 Cache TagHelper 实现使用 IMemoryCache.

的实例