Skip to content

Commit f2e458f

Browse files
committed
Release: 1.0.1
1 parent 6ca9795 commit f2e458f

8 files changed

Lines changed: 117 additions & 20 deletions

File tree

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,62 @@
11
# Cache
22

3-
## This is an add-in for [Fody](https://github.com/Fody/Fody/)
4-
53
<img src="https://github.com/KevinYeti/Cache/raw/master/icon.png" width="64">
64

75
Injects method cache code.
86

7+
### This is an add-in for [Fody](https://github.com/Fody/Fody/)
98
[Introduction to Fody](http://github.com/Fody/Fody/wiki/SampleUsage)
109

10+
This project was forked by [MethodTimer](https://github.com/Fody/MethodTimer) original.
11+
And updated to support DotNet Core.
12+
1113
## Milestone
14+
- [x] Support dotnet core
1215
- [x] Support instance of class cache
1316
- [x] Support static of method cache
1417
- [ ] Support property of class cache
1518
- [ ] Support complex parameters of method cache
1619

20+
## Your Code
21+
22+
[Cache]
23+
public int Add(int a, int b)
24+
{
25+
return a + b;
26+
}
27+
28+
[Cache]
29+
public string AlsoWorksForProperties
30+
{
31+
get
32+
{
33+
return DoSomeCalculations(this.parameterField);
34+
}
35+
set
36+
{
37+
this.parameterField = value;
38+
}
39+
}
40+
41+
## What gets compiled
42+
43+
public int Add(int a, int b)
44+
{
45+
string cacheKey = string.Format("Namespace.Class.Add_{0}_{1}", new object[] { a, b });
46+
47+
if(Cache.Contains(cacheKey))
48+
{
49+
return Cache.Retrieve<int>(cacheKey);
50+
}
51+
52+
int result = a + b;
53+
54+
Cache.Store(cacheKey, result);
55+
56+
return result;
57+
}
58+
59+
1760
## Usage
1861

1962
See also [Fody usage](https://github.com/Fody/Fody#usage).

src/AssemblyToReference/NormalClass.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ static NormalClass()
6666
// return 3.14M;
6767
//}
6868

69-
//[Cache]
70-
//public decimal Calc2(int a, int b)
71-
//{
72-
// Thread.Sleep(10000);
73-
// return 3.14M;
74-
//}
69+
[Cache]
70+
public decimal Calc2(int a, int b)
71+
{
72+
Thread.Sleep(10000);
73+
return 3.14M;
74+
}
7575

7676
//[Cache]
7777
//public decimal Calc3(int a, Dictionary<int, string> list)

src/AssemblyToReference/RuntimeCache.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
1+
using Cache;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
67

78
namespace AssemblyToReference
89
{
9-
public class RuntimeCache
10+
public class RuntimeCache : ICacheProvider
1011
{
1112
public RuntimeCache()
1213
{

src/Cache.Attribute/Cache.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
<PropertyGroup>
44
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
55
<PackageVersion>1.0.1</PackageVersion>
6-
<Description>Cache</Description>
7-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
6+
<Description>Injects method cache code.</Description>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<PackageProjectUrl>https://github.com/KevinYeti/Cache</PackageProjectUrl>
9+
<PackageIconUrl>https://raw.githubusercontent.com/KevinYeti/Cache/master/icon.png</PackageIconUrl>
10+
<PackageTags>Cache, ILWeaving, Fody, Cecil, AOP</PackageTags>
11+
<PackageLicenseUrl>https://github.com/KevinYeti/Cache/blob/master/LICENSE</PackageLicenseUrl>
12+
<PackageId>Cache.Fody</PackageId>
13+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
14+
<FileVersion>1.0.1.0</FileVersion>
15+
<Version>1.0.1</Version>
816
</PropertyGroup>
917

1018
<ItemGroup>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Cache
8+
{
9+
public interface ICacheProvider
10+
{
11+
bool Contains(string key);
12+
13+
T Retrieve<T>(string key);
14+
15+
void Store(string key, object data);
16+
17+
// Remove is needed for writeable properties which must invalidate the Cache
18+
// You can skip this method but then only readonly properties are supported
19+
void Remove(string key);
20+
21+
}
22+
}

src/Cache.Attribute/ICacheable.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Cache
8+
{
9+
interface ICacheable
10+
{
11+
}
12+
}

src/Cache.Fody/Cache.Fody.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
<PropertyGroup>
44
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
55
<PackageVersion>1.0.1</PackageVersion>
6-
<Description>Cache.Fody</Description>
6+
<Description>Injects method cache code.</Description>
7+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
8+
<PackageId></PackageId>
9+
<Authors>Cache.Fody</Authors>
10+
<PackageLicenseUrl>https://github.com/KevinYeti/Cache/blob/master/LICENSE</PackageLicenseUrl>
11+
<Copyright></Copyright>
12+
<PackageProjectUrl>https://github.com/KevinYeti/Cache</PackageProjectUrl>
13+
<PackageIconUrl>https://raw.githubusercontent.com/KevinYeti/Cache/master/icon.png</PackageIconUrl>
14+
<PackageTags>Cache, ILWeaving, Fody, Cecil, AOP</PackageTags>
15+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
16+
<FileVersion>1.0.1.0</FileVersion>
17+
<Version>1.0.1</Version>
718
</PropertyGroup>
819

920
<ItemGroup>

src/Tests/UnitTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ static UnitTest()
1717
testResult = weavingTask.ExecuteTestRun("AssemblyToReference.dll", false);
1818
}
1919

20-
//[Fact]
21-
//public void InstanceClassTest()
22-
//{
23-
// var type = testResult.Assembly.GetType("AssemblyToReference.NormalClass", true);
24-
// var instance = (dynamic)Activator.CreateInstance(type);
20+
[Fact]
21+
public void InstanceClassTest()
22+
{
23+
var type = testResult.Assembly.GetType("AssemblyToReference.NormalClass", true);
24+
var instance = (dynamic)Activator.CreateInstance(type);
2525

26-
// Assert.Equal(3.14M, instance.Calc2(1, 2));
27-
//}
26+
Assert.Equal(3.14M, instance.Calc2(1, 2));
27+
}
2828

2929
//[Fact]
3030
//public void InstanceClassTestWithGeneric()

0 commit comments

Comments
 (0)