Skip to content

Commit 132a38d

Browse files
committed
📝 Update Doc
1 parent f19ab09 commit 132a38d

File tree

9 files changed

+293
-41
lines changed

9 files changed

+293
-41
lines changed

docs/CSRedis.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ public class Startup
3939
ConnectionStrings = new System.Collections.Generic.List<string>
4040
{
4141
"127.0.0.1:6388,defaultDatabase=13,poolsize=10"
42-
}
42+
},
43+
// the sentinels settings
44+
Sentinels = new System.Collections.Generic.List<string>
45+
{
46+
"192.169.1.10:26379", "192.169.1.11:26379", "192.169.1.12:26379"
47+
},
48+
// the read write setting for sentinel mode
49+
ReadOnly = false
4350
};
4451
});
4552
});
@@ -79,7 +86,11 @@ public class Startup
7986
"dbconfig": {
8087
"ConnectionStrings":[
8188
"127.0.0.1:6388,defaultDatabase=13,poolsize=10"
82-
]
89+
],
90+
"Sentinels":[
91+
"192.169.1.10:26379", "192.169.1.11:26379", "192.169.1.12:26379"
92+
],
93+
"ReadOnly": false
8394
}
8495
}
8596
}

docs/EasyCachingProvider.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# EasyCachingProvider
2+
3+
EasyCachingProvider can be created by `IEasyCachingProviderFactory`.
4+
5+
# How to Use?
6+
7+
## 1. Install the packages via Nuget
8+
9+
```
10+
Install-Package EasyCaching.InMemory
11+
```
12+
13+
## 2. Config in Startup class
14+
15+
```csharp
16+
public void ConfigureServices(IServiceCollection services)
17+
{
18+
//other ..
19+
20+
services.AddEasyCaching(option=>
21+
{
22+
//use memory cache
23+
option.UseInMemory("inmemory1");
24+
25+
//use memory cache
26+
option.UseInMemory("inmemory2");
27+
});
28+
}
29+
```
30+
31+
### 3. Call the IEasyCachingProviderFactory
32+
33+
Following code shows how to use IEasyCachingProviderFactory in ASP.NET Core Web API.
34+
35+
```csharp
36+
[Route("api/[controller]")]
37+
public class ValuesController : Controller
38+
{
39+
private readonly IEasyCachingProviderFactory _factory;
40+
41+
public ValuesController(IEasyCachingProviderFactory factory)
42+
{
43+
this._factory = factory;
44+
}
45+
46+
// GET api/values/inmem1
47+
[HttpGet]
48+
[Route("inmem1")]
49+
public string GetInMemory()
50+
{
51+
var provider = _factory.GetCachingProvider("inmemory1");
52+
var val = $"memory1-{Guid.NewGuid()}";
53+
var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1));
54+
Console.WriteLine($"Type=InMemory,Key=named-provider,Value={res},Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
55+
return $"cached value : {res}";
56+
}
57+
58+
// GET api/values/inmem2
59+
[HttpGet]
60+
[Route("inmem2")]
61+
public string GetInMemory()
62+
{
63+
var provider = _factory.GetCachingProvider("inmemory2");
64+
var val = $"memory2-{Guid.NewGuid()}";
65+
var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1));
66+
Console.WriteLine($"Type=InMemory,Key=named-provider,Value={res},Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
67+
return $"cached value : {res}";
68+
}
69+
}
70+
```

docs/FactoryOverview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
The main purpose of the cache factory is to solve the problem of multiple instances. Multiple instances can be understood as the use of multiple different providers in a project, such as an InMemory with a CSRedis, three InMemory and two InMemory with two CSRedis.
44

5-
65
In EasyCaching, all different types of providers can be create by the factory:
76

87
- IEasyCachingProvider

docs/Features.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
2. Get/GetAsync(without data retriever)
66
3. Set/SetAsync
77
4. Remove/RemoveAsync
8-
5. Refresh/RefreshAsync
8+
5. ~~Refresh/RefreshAsync (was removed)~~
99
6. RemoveByPrefix/RemoveByPrefixAsync
1010
7. SetAll/SetAllAsync
1111
8. GetAll/GetAllAsync
@@ -22,6 +22,7 @@
2222
4. Redis(Based on csredis)
2323
5. SQLite
2424
6. Hybrid
25+
7. Disk
2526
- Caching Interceptors
2627
1. AspectCore
2728
2. Castle

docs/HybridCachingProvider.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# HybridCachingProvider
2+
3+
HybridCachingProvider can be created by `IHybridProviderFactory`.
4+
5+
# How to Use?
6+
7+
## 1. Install the packages via Nuget
8+
9+
```
10+
Install-Package EasyCaching.HybridCache
11+
Install-Package EasyCaching.InMemory
12+
Install-Package EasyCaching.Redis
13+
Install-Package EasyCaching.Bus.Redis
14+
```
15+
16+
## 2. Config in Startup class
17+
18+
```csharp
19+
public void ConfigureServices(IServiceCollection services)
20+
{
21+
//other ..
22+
23+
services.AddEasyCaching(options =>
24+
{
25+
// local
26+
options.UseInMemory("m1");
27+
// distributed
28+
options.UseRedis(config =>
29+
{
30+
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
31+
config.DBConfig.Database = 5;
32+
}, "myredis");
33+
34+
// combine local and distributed
35+
options.UseHybrid(config =>
36+
{
37+
config.TopicName = "test-topic";
38+
config.EnableLogging = true;
39+
40+
// specify the local cache provider name after v0.5.4
41+
config.LocalCacheProviderName = "m1";
42+
// specify the distributed cache provider name after v0.5.4
43+
config.DistributedCacheProviderName = "myredis";
44+
}, "h1")
45+
// use redis bus
46+
.WithRedisBus(busConf =>
47+
{
48+
busConf.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
49+
});
50+
});
51+
}
52+
```
53+
54+
### 3. Call the IHybridCachingProvider
55+
56+
Following code shows how to use IHybridCachingProvider in ASP.NET Core Web API.
57+
58+
```csharp
59+
[Route("api/[controller]")]
60+
[ApiController]
61+
public class ValuesController : ControllerBase
62+
{
63+
private readonly IHybridCachingProvider _hybrid;
64+
65+
public ValuesController(IHybridProviderFactory hybridFactory)
66+
{
67+
this._hybrid = hybridFactory.GetHybridCachingProvider("h1");
68+
}
69+
70+
// GET api/values
71+
[HttpGet]
72+
public ActionResult<IEnumerable<string>> Get()
73+
{
74+
var res = _hybrid.Get<string>("cacheKey");
75+
76+
return new string[] { "value1", "value2", res.Value };
77+
}
78+
79+
// GET api/values/set
80+
[HttpGet("set")]
81+
public ActionResult<string> Set()
82+
{
83+
// the same key for different value of
84+
_hybrid.Set("cacheKey", "val-from app1", TimeSpan.FromMinutes(1));
85+
86+
return "ok";
87+
}
88+
}
89+
```

docs/In-Memory.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,35 @@ public class Startup
2828
//other services.
2929
3030
//Important step for In-Memory Caching
31-
services.AddEasyCaching(option =>
31+
services.AddEasyCaching(options =>
3232
{
3333
// use memory cache with a simple way
34-
option.UseInMemory("default");
34+
options.UseInMemory("default");
3535

3636
// use memory cache with your own configuration
37-
config.UseInMemory(options =>
37+
options.UseInMemory(config =>
3838
{
39-
options.DBConfig = new InMemoryCachingOptions
39+
config.DBConfig = new InMemoryCachingOptions
4040
{
4141
// scan time, default value is 60s
4242
ExpirationScanFrequency = 60,
4343
// total count of cache items, default value is 10000
44-
SizeLimit = 100
44+
SizeLimit = 100,
45+
46+
// below two settings are added in v0.8.0
47+
// enable deep clone when reading object from cache or not, default value is true.
48+
EnableReadDeepClone = true,
49+
// enable deep clone when writing object to cache or not, default valuee is false.
50+
EnableWriteDeepClone = false,
4551
};
4652
// the max random second will be added to cache's expiration, default value is 120
47-
options.MaxRdSecond = 120;
53+
config.MaxRdSecond = 120;
4854
// whether enable logging, default is false
49-
options.EnableLogging = false;
55+
config.EnableLogging = false;
5056
// mutex key's alive time(ms), default is 5000
51-
options.LockMs = 5000;
57+
config.LockMs = 5000;
5258
// when mutex key alive, it will sleep some time, default is 300
53-
options.SleepMs = 300;
59+
config.SleepMs = 300;
5460
}, "default1");
5561
});
5662
}
@@ -69,10 +75,10 @@ public class Startup
6975
//other services.
7076
7177
//Important step for In-Memory Caching
72-
services.AddEasyCaching(option =>
78+
services.AddEasyCaching(options =>
7379
{
7480
//use memory cache
75-
option.UseInMemory(Configuration, "default", "easycahing:inmemory");
81+
options.UseInMemory(Configuration, "default", "easycahing:inmemory");
7682
});
7783
}
7884
}
@@ -89,7 +95,9 @@ public class Startup
8995
"SleepMs": 300,
9096
"DBConfig":{
9197
"SizeLimit": 10000,
92-
"ExpirationScanFrequency": 60
98+
"ExpirationScanFrequency": 60,
99+
"EnableReadDeepClone": true,
100+
"EnableWriteDeepClone": false
93101
}
94102
}
95103
}
@@ -138,4 +146,10 @@ public class ValuesController : Controller
138146
var res = await _provider.GetAsync<string>("demo");
139147
}
140148
}
141-
```
149+
```
150+
151+
## Precautions
152+
153+
If you need to modify the data after you read from cache, don't forget the enable deep clone, otherwise, the cached data will be modified.
154+
155+
By the way, deep clone will hurt the performance, so if you don't need it, you should disable.

docs/Memcached.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ public class Startup
3535
});
3636
});
3737
}
38-
39-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
40-
{
41-
// Important step for Memcache Cache
42-
app.UseEasyCaching();
43-
}
4438
}
4539
```
4640

@@ -85,12 +79,6 @@ public class ValuesController : Controller
8579

8680
//Get without data retriever Async
8781
var res = await _provider.GetAsync<string>("demo");
88-
89-
//Refresh
90-
_provider.Refresh("key", "123", TimeSpan.FromMinutes(1));
91-
92-
//Refresh Async
93-
await _provider.RefreshAsync("key", "123", TimeSpan.FromMinutes(1));
9482
}
9583
}
9684
```

0 commit comments

Comments
 (0)