Asp.net core 静态Id-ASP.NET核心分布式缓存标记帮助器
我们将ASP.NET Core分布式缓存标记帮助程序与SQL server一起使用Asp.net core 静态Id-ASP.NET核心分布式缓存标记帮助器,asp.net-core,razor-pages,distributed-caching,Asp.net Core,Razor Pages,Distributed Caching,我们将ASP.NET Core分布式缓存标记帮助程序与SQL server一起使用 <distributed-cache name="MyCacheItem1" expires-after="TimeSpan.FromDays(1)"> <p>Something that will be cached</p> @DateTime.Now.ToString() </distributed-cache>
<distributed-cache name="MyCacheItem1" expires-after="TimeSpan.FromDays(1)">
<p>Something that will be cached</p>
@DateTime.Now.ToString()
</distributed-cache>
将被缓存的东西
@DateTime.Now.ToString()
它存储如下。
问题是Id列是自动散列的。我们希望Id列中有一些有意义的字符串。
可能吗
问题是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
列提供未删除的数据,您可以参考DistributedCacheTagHelper
和DistributedCacheTagHelperService
的源代码,然后实现一个自定义标记helper。谢谢@Fei Han。我从你的回答中得到了线索
在Id列中存储自定义字符串。按照步骤操作
if (output.Attributes != null && output.Attributes.Count > 0 &&
string.Equals(output.Attributes[0].Name, "htmlcache-uniqueid") &&
output.Attributes[0].Value != null)
{
storageKey = Convert.ToString(output.Attributes[0].Value);
}