Can I be sure that .Method.MethodHandle.GetFunctionPointer() is unique for each anonymous function?
Want to do
public static T Get<T>(Func<T> getDataCallback) where T : class
{
string cacheID = getDataCallback.Method.MethodHandle.GetFunctionPointer().ToString();
var data = HttpRuntime.Cache.Get(cacheID) as T;
if (data == null)
{
data = getDataCallback();
HttpContext.Current.Cache.Insert(cacheID, data);
}
return data;
}
I think you mean anonymous delegates. Different delegates have different
d.Method.MethodHandle.GetFunctonPointer()results, but first we need to define “different delegates”. If two delegates refers to the same method, they are considered the same, like:Anonymous delegates are always different, even they look the same:
So the answer to your first question is YES, but your cache possibly won’t work as expected! If your application pool is recycled, the FunctionPointer value will change even your
getDataCallbackdelegate remains the same. Be aware of this.