@@ -74,20 +74,26 @@ public Type GetProxyType()
7474 {
7575 bool notFoundInTypeCache = false ;
7676
77- var proxyType = Scope . TypeCache . GetOrAdd ( GetCacheKey ( ) , cacheKey =>
77+ var cacheKey = GetCacheKey ( ) ;
78+ if ( ! Scope . TryGetTypeFromCache ( cacheKey , out var proxyType ) )
7879 {
79- notFoundInTypeCache = true ;
80- Logger . DebugFormat ( "No cached proxy type was found for target type {0}." , targetType . FullName ) ;
80+ proxyType = Scope . GetOrAddFromCache ( cacheKey , key =>
81+ {
82+ notFoundInTypeCache = true ;
83+
84+ Logger . DebugFormat ( "No cached proxy type was found for target type {0}." , targetType . FullName ) ;
8185
82- EnsureOptionsOverrideEqualsAndGetHashCode ( ) ;
86+ EnsureOptionsOverrideEqualsAndGetHashCode ( ) ;
8387
84- var name = Scope . NamingScope . GetUniqueName ( "Castle.Proxies." + targetType . Name + "Proxy" ) ;
85- return GenerateType ( name , Scope . NamingScope . SafeSubScope ( ) ) ;
86- } ) ;
88+ var name = Scope . NamingScope . GetUniqueName ( "Castle.Proxies." + targetType . Name + "Proxy" ) ;
89+ return GenerateType ( name , Scope . NamingScope . SafeSubScope ( ) ) ;
90+ } ) ;
91+ }
8792
8893 if ( ! notFoundInTypeCache )
8994 {
90- Logger . DebugFormat ( "Found cached proxy type {0} for target type {1}." , proxyType . FullName , targetType . FullName ) ;
95+ if ( Logger . IsDebugEnabled )
96+ Logger . DebugFormat ( "Found cached proxy type {0} for target type {1}." , proxyType . FullName , targetType . FullName ) ;
9197 }
9298
9399 return proxyType ;
0 commit comments