首页 > 解决方案 > 静态 ID - ASP.NET Core 分布式缓存标记帮助程序

问题描述

我们将 ASP.NET Core 分布式缓存标记助手与 SQL 服务器一起使用。

<distributed-cache name="MyCacheItem1" expires-after="TimeSpan.FromDays(1)">
   <p>Something that will be cached</p>
   @DateTime.Now.ToString()
</distributed-cache>

它存储如下。 在此处输入图像描述

问题是 Id 列是自动散列的。我们希望在 Id 列中有一些有意义的字符串。是否可以?

标签: asp.net-corerazor-pagesdistributed-caching

解决方案


问题是 Id 列是自动散列的。

从源代码中,我们可以发现这似乎是一种设计行为:

try
{
    var serializedKey = Encoding.UTF8.GetBytes(key.GenerateKey());
    var storageKey = key.GenerateHashedKey();
    var value = await _storage.GetAsync(storageKey);

    //...

    //...

    await _storage.SetAsync(storageKey, encodeValue, options);

我们希望在 Id 列中有一些有意义的字符串。是否可以?

如果您有特定的场景/要求需要对Id列进行未哈希处理的数据,您可以参考 and 的源代码DistributedCacheTagHelperDistributedCacheTagHelperService然后实现自定义标签助手。


推荐阅读