asp.net-core - 静态 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 列中有一些有意义的字符串。是否可以?
解决方案
问题是 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 的源代码DistributedCacheTagHelper
,DistributedCacheTagHelperService
然后实现自定义标签助手。
推荐阅读
- mysql - 编写查询以从 MySQL 表中删除重复行?
- arrays - 如何按 ID 数据分组(映射)?
- python - 在 spacy 中,如何确保始终将特定字符视为完整标记?
- react-native - 有没有办法在 React Native 中将应用程序变成网站?
- .net-core - EF Core 迁移在程序集中找不到上下文类型
- discord - 是否可以从 Discod.js 机器人的用户名中 DM 用户
- html - what type of element is possible to use as a grid element?
- c# - .netcore 套接字中断,而经典 .net 仍然有效
- node.js - 如何从节点 js 服务器向客户端发送 json 数据?
- macos - 如何从 Mac 命令行启动 Launchpad 或 Mission Control (Exposè)?