@@ -8,74 +8,86 @@ namespace Microsoft.AspNet.Http.Features
88 internal sealed class FeatureHelpers
99 {
1010 public static T GetAndCache < T > (
11- IFeatureCache cache ,
12- IFeatureCollection features ,
13- ref T cachedObject )
11+ IFeatureCache cache ,
12+ IFeatureCollection features ,
13+ ref T cachedObject )
1414 {
1515 cache . CheckFeaturesRevision ( ) ;
16- if ( cachedObject == null )
16+
17+ T obj = cachedObject ;
18+ if ( obj == null )
1719 {
18- cachedObject = features . Get < T > ( ) ;
20+ obj = features . Get < T > ( ) ;
21+ cachedObject = obj ;
1922 }
20- return cachedObject ;
23+ return obj ;
2124 }
2225
2326 public static T GetOrCreateAndCache < T > (
24- IFeatureCache cache ,
25- IFeatureCollection features ,
26- Func < T > factory ,
27- ref T cachedObject )
27+ IFeatureCache cache ,
28+ IFeatureCollection features ,
29+ Func < T > factory ,
30+ ref T cachedObject )
2831 {
2932 cache . CheckFeaturesRevision ( ) ;
30- if ( cachedObject == null )
33+
34+ T obj = cachedObject ;
35+ if ( obj == null )
3136 {
32- cachedObject = features . Get < T > ( ) ;
33- if ( cachedObject == null )
37+ obj = features . Get < T > ( ) ;
38+ if ( obj == null )
3439 {
35- cachedObject = factory ( ) ;
36- features . Set ( cachedObject ) ;
40+ obj = factory ( ) ;
41+ cachedObject = obj ;
42+ features . Set ( obj ) ;
3743 }
3844 }
39- return cachedObject ;
45+ return obj ;
4046 }
4147
4248 public static T GetOrCreateAndCache < T > (
43- IFeatureCache cache ,
44- IFeatureCollection features ,
45- Func < IFeatureCollection , T > factory ,
46- ref T cachedObject )
49+ IFeatureCache cache ,
50+ IFeatureCollection features ,
51+ Func < IFeatureCollection , T > factory ,
52+ ref T cachedObject )
4753 {
4854 cache . CheckFeaturesRevision ( ) ;
49- if ( cachedObject == null )
55+
56+ T obj = cachedObject ;
57+ if ( obj == null )
5058 {
51- cachedObject = features . Get < T > ( ) ;
52- if ( cachedObject == null )
59+ obj = features . Get < T > ( ) ;
60+ if ( obj == null )
5361 {
54- cachedObject = factory ( features ) ;
55- features . Set ( cachedObject ) ;
62+ obj = factory ( features ) ;
63+ cachedObject = obj ;
64+ features . Set ( obj ) ;
5665 }
5766 }
58- return cachedObject ;
67+ return obj ;
5968 }
6069
6170 public static T GetOrCreateAndCache < T > (
62- IFeatureCache cache ,
63- IFeatureCollection features ,
64- HttpRequest request ,
65- Func < HttpRequest , T > factory ,
66- ref T cachedObject )
71+ IFeatureCache cache ,
72+ IFeatureCollection features ,
73+ HttpRequest request ,
74+ Func < HttpRequest , T > factory ,
75+ ref T cachedObject )
6776 {
6877 cache . CheckFeaturesRevision ( ) ;
69- if ( cachedObject == null )
78+
79+ T obj = cachedObject ;
80+ if ( obj == null )
7081 {
71- cachedObject = features . Get < T > ( ) ;
72- if ( cachedObject == null )
82+ obj = features . Get < T > ( ) ;
83+ if ( obj == null )
7384 {
74- cachedObject = factory ( request ) ;
75- features . Set ( cachedObject ) ;
85+ obj = factory ( request ) ;
86+ cachedObject = obj ;
87+ features . Set ( obj ) ;
7688 }
7789 }
78- return cachedObject ;
90+ return obj ;
7991 }
8092 }
8193}
0 commit comments