我正在尝试在 MemoryCache 对象中缓存昂贵函数的结果。
MemoryCache 需要一个字符串键,所以我想知道执行以下操作是否有效:
string key = Char.ConvertFromUtf32(myObject.GetHashCode());
if (!_resourceDescriptionCache.Contains(key))
{
_resourceDescriptionCache[key] = ExpensiveFunction(myObject);
}
return (string)_resourceDescriptionCache[key];
使用单个 UTF32 字符作为潜在大缓存的键感觉很奇怪。