internal MemoizerConfiguration(object function, ExpirationType expirationType, int expirationValue, TimeUnit expirationTimeUnit, Action <string> loggerMethod) { Function = function; bool firstTime = false; //this.FunctionId = (Int32)MemoizerHelper.GetObjectId(Function, ref firstTime); this.FunctionId = (Int32)HashHelper.GetObjectId(Function, ref firstTime); ExpirationType = expirationType; ExpirationValue = expirationValue; ExpirationTimeUnit = expirationTimeUnit; LoggerAction = loggerMethod; }
/// <summary> /// Coupled with the <code>MemoizerConfiguration.GetHashCode()</code> method. /// </summary> /// <param name="function">The memoized function to look for</param> /// <param name="memoizerRegistry">The memoizer registry instance to look into</param> /// <returns>An enumeration of keys pointing to memoizer instances in the memoizer registry, having the given function</returns> internal static IEnumerable <string> FindMemoizerKeysInRegistryHavingFunction <T>(object function, Memoizer <MemoizerConfiguration, T> memoizerRegistry) { IList <string> memoizerKeyList = new List <string>(); foreach (KeyValuePair <string, object> keyValuePair in memoizerRegistry.cache) { string funcIdPartOfMemoizerConfigurationHashCode = keyValuePair.Key.PadLeft(10, '0').Substring(0, 5); bool firstTime = false; //long funcId_long = MemoizerHelper.GetObjectId(function, ref firstTime); long funcId_long = HashHelper.GetObjectId(function, ref firstTime); if (funcId_long > 21474) { throw new InvalidOperationException("Memoizer.NET only supports 21474 different Func references at the moment..."); } string funcIdPartOfFunctionToLookFor = funcId_long.ToString().PadLeft(5, '0'); if (funcIdPartOfFunctionToLookFor == funcIdPartOfMemoizerConfigurationHashCode) { memoizerKeyList.Add(keyValuePair.Key); } } return(memoizerKeyList); }