We are using ASP.NET Core Distributed Cache Tag Helper with SQL server.
<distributed-cache name="MyCacheItem1" expires-after="TimeSpan.FromDays(1)">
<p>Something that will be cached</p>
@DateTime.Now.ToString()
</distributed-cache>
The problem is that Id column is automatically hashed. we want some meaningful string in Id column. Is it possible?
Thank you @Fei Han. I got clue from your answer.
To store custom string in Id column. Follow the steps.
Implement custom class using IDistributedCacheTagHelperService ( I created like HtmlDistributedCacheTagHelperService)
Inject this custom class in startup. services.AddScoped<IDistributedCacheTagHelperService, HtmlDistributedCacheTagHelperService>();
Copy actual source code of DistributedCacheTagHelperService (https://github.com/dotnet/aspnetcore/blob/52eff90fbcfca39b7eb58baad597df6a99a542b0/src/Mvc/Mvc.TagHelpers/src/Cache/DistributedCacheTagHelperService.cs#L102). and paste inside HtmlDistributedCacheTagHelperService.
I added custom attribute htmlcache-uniqueid. <distributed-cache name="UniqueName" htmlcache-uniqueid="CustomStringId">
Inside HtmlDistributedCacheTagHelperService class i added below code to get my custom attribute.
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);
}