@@ -29,7 +29,7 @@ Add `<SpatialFocus.MethodCache/>` to [FodyWeavers.xml](https://github.com/Fody/H
2929
3030``` xml
3131<Weavers >
32- <SpatialFocus .MethodCache/>
32+ <SpatialFocus .MethodCache/>
3333</Weavers >
3434```
3535
@@ -41,18 +41,19 @@ Before code:
4141[Cache ]
4242public class BasicSample
4343{
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+ }
5657}
5758```
5859
@@ -62,30 +63,30 @@ What gets compiled
6263[Cache ]
6364public class BasicSample
6465{
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+ }
7170
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 ; }
7772
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 )
8074 {
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 ;
8289 }
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- }
8990}
9091```
9192
0 commit comments