private string GetCacheKey(object instance, Arguments arguments) { // If we have no argument, return just the method name so we don't uselessly allocate memory. if (instance == null && arguments.Count == 0) return this._methodName; // Add all arguments to the cache key. Note that generic arguments are not part of the cache // key, so method calls that differ only by generic arguments will have conflicting cache keys. StringBuilder stringBuilder = new StringBuilder(this._methodName); stringBuilder.Append('('); if (instance != null) { stringBuilder.Append(instance); stringBuilder.Append("; "); } for (int i = 0; i < arguments.Count; i++) { stringBuilder.Append(arguments.GetArgument(i) ?? "null"); stringBuilder.Append(", "); } return stringBuilder.ToString(); }
public string BuildCacheKey(object instance, Arguments arguments) { StringBuilder cacheKeyBuilder = new StringBuilder(); // start building a key based on the method name if a group name not set if (string.IsNullOrWhiteSpace(GroupName)) { cacheKeyBuilder.Append(MethodName); } else { cacheKeyBuilder.Append(GroupName); } if (instance != null) { cacheKeyBuilder.Append(instance); cacheKeyBuilder.Append(";"); } int argIndex; switch (Settings) { case CacheSettings.IgnoreParameters: return cacheKeyBuilder.ToString(); case CacheSettings.UseId: argIndex = GetArgumentIndexByName("Id"); cacheKeyBuilder.Append(arguments.GetArgument(argIndex) ?? "Null"); break; case CacheSettings.UseProperty: argIndex = GetArgumentIndexByName(ParameterProperty); cacheKeyBuilder.Append(arguments.GetArgument(argIndex) ?? "Null"); break; case CacheSettings.Default: for (var i = 0; i < arguments.Count; i++) { BuildDefaultKey(arguments.GetArgument(i), cacheKeyBuilder); } break; } return cacheKeyBuilder.ToString(); }