@@ -29,7 +29,7 @@ Add `<SpatialFocus.MethodCache/>` to [FodyWeavers.xml](https://github.com/Fody/H
29
29
30
30
``` xml
31
31
<Weavers >
32
- <SpatialFocus .MethodCache/>
32
+ <SpatialFocus .MethodCache/>
33
33
</Weavers >
34
34
```
35
35
@@ -41,18 +41,19 @@ Before code:
41
41
[Cache ]
42
42
public class BasicSample
43
43
{
44
- public BasicSample (IMemoryCache memoryCache )
45
- {
46
- MemoryCache = memoryCache ;
47
- }
48
-
49
- // MethodCache.Fody will look for a property implementing the Microsoft.Extensions.Caching.Memory.IMemoryCache interface
50
- protected IMemoryCache MemoryCache { get ; }
51
-
52
- public int Add (int a , int b )
53
- {
54
- return a + b ;
55
- }
44
+ public BasicSample (IMemoryCache memoryCache )
45
+ {
46
+ MemoryCache = memoryCache ;
47
+ }
48
+
49
+ // MethodCache.Fody will look for a property implementing
50
+ // the Microsoft.Extensions.Caching.Memory.IMemoryCache interface
51
+ protected IMemoryCache MemoryCache { get ; }
52
+
53
+ public int Add (int a , int b )
54
+ {
55
+ return a + b ;
56
+ }
56
57
}
57
58
```
58
59
@@ -62,30 +63,30 @@ What gets compiled
62
63
[Cache ]
63
64
public class BasicSample
64
65
{
65
- public BasicSample (IMemoryCache memoryCache )
66
- {
67
- MemoryCache = memoryCache ;
68
- }
69
-
70
- protected IMemoryCache MemoryCache { get ; }
66
+ public BasicSample (IMemoryCache memoryCache )
67
+ {
68
+ MemoryCache = memoryCache ;
69
+ }
71
70
72
- public int Add (int a , int b )
73
- {
74
- // Create a unique cache key, based on namespace, class name and method name as first parameter and corresponding
75
- // generic class parameters, generic method parameters and method parameters
76
- Tuple < string , int , int > key = new Tuple <string , int , int >(" Namespace.BasicSample.Add" , a , b );
71
+ protected IMemoryCache MemoryCache { get ; }
77
72
78
- // Check and return if a cached value exists for key
79
- if (MemoryCache .TryGetValue (key , out int value ))
73
+ public int Add (int a , int b )
80
74
{
81
- return value ;
75
+ // Create a unique cache key, based on namespace, class name and method name as first parameter
76
+ // and corresponding generic class parameters, generic method parameters and method parameters
77
+ Tuple < string , int , int > key = new Tuple <string , int , int >(" Namespace.BasicSample.Add" , a , b );
78
+
79
+ // Check and return if a cached value exists for key
80
+ if (MemoryCache .TryGetValue (key , out int value ))
81
+ {
82
+ return value ;
83
+ }
84
+
85
+ // Before each return statement, save the value that would be returned in the cache
86
+ value = a + b ;
87
+ MemoryCache .Set <int >(key , value );
88
+ return value ;
82
89
}
83
-
84
- // Before each return statement, save the value that would be returned in the cache
85
- value = a + b ;
86
- MemoryCache .Set <int >(key , value );
87
- return value ;
88
- }
89
90
}
90
91
```
91
92
0 commit comments