Skip to content

Commit 0f2d17a

Browse files
authored
📝 Update README.md
Add the usages about IEasyCachingProviderFactory
1 parent f978a35 commit 0f2d17a

File tree

1 file changed

+57
-59
lines changed

1 file changed

+57
-59
lines changed

README.md

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ EasyCaching is an open source caching library that contains basic usages and som
99

1010
## CI Build Status
1111

12-
| Platform | Build Server | Status |
13-
|--------- |------------- |---------|
14-
| AppVeyor | Windows |[![Build status](https://ci.appveyor.com/api/projects/status/4x6qal9c1r10wn6x?svg=true)](https://ci.appveyor.com/project/catcherwong/easycaching-48okb) |
15-
| Travis | Linux/OSX | [![Build Status](https://travis-ci.org/dotnetcore/EasyCaching.svg?branch=master)](https://travis-ci.org/dotnetcore/EasyCaching) |
12+
| Platform | Build Server | Master Status | Dev Status |
13+
|--------- |------------- |---------|---------|
14+
| AppVeyor | Windows/Linux |[![Build status](https://ci.appveyor.com/api/projects/status/4x6qal9c1r10wn6x/branch/master?svg=true)](https://ci.appveyor.com/project/catcherwong/easycaching-48okb/branch/master) |[![Build status](https://ci.appveyor.com/api/projects/status/4x6qal9c1r10wn6x/branch/dev?svg=true)](https://ci.appveyor.com/project/catcherwong/easycaching-48okb/branch/dev)|
15+
| Travis | Linux/OSX | [![Build Status](https://travis-ci.org/dotnetcore/EasyCaching.svg?branch=master)](https://travis-ci.org/dotnetcore/EasyCaching) | [![Build Status](https://travis-ci.org/dotnetcore/EasyCaching.svg?branch=dev)](https://travis-ci.org/dotnetcore/EasyCaching) |
1616

1717
## Nuget Packages
1818

@@ -53,7 +53,7 @@ EasyCaching is an open source caching library that contains basic usages and som
5353
|--------------| ------- | ----
5454
| EasyCaching.ResponseCaching | ![](https://img.shields.io/nuget/v/EasyCaching.ResponseCaching.svg) | ![](https://img.shields.io/nuget/dt/EasyCaching.ResponseCaching.svg)
5555

56-
## Basci Usages
56+
## Basic Usages
5757

5858
### Step 1 : Install the package
5959

@@ -70,7 +70,7 @@ Install-Package EasyCaching.Memcached
7070

7171
Different types of caching hvae their own way to config.
7272

73-
Here are samples show you how to config.
73+
Here is a sample show you how to config.
7474

7575
```csharp
7676
public class Startup
@@ -81,62 +81,12 @@ public class Startup
8181
{
8282
services.AddMvc();
8383

84-
//1. In-Memory Cache
84+
//In-Memory Cache
8585
services.AddDefaultInMemoryCache();
8686

8787
//Read from appsetting.json
88-
//services.AddDefaultInMemoryCache(Configuration);
89-
90-
////2. Important step for using Memcached Cache
91-
//services.AddDefaultMemcached(op =>
92-
//{
93-
// op.DBConfig.AddServer("127.0.0.1", 11211);
94-
//});
95-
96-
//services.AddDefaultMemcached(Configuration);
97-
98-
//3. Important step for using Redis Cache
99-
//services.AddDefaultRedisCache(option =>
100-
//{
101-
// option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
102-
// option.DBConfig.Password = "";
103-
//});
104-
105-
//services.AddDefaultRedisCache(Configuration);
106-
107-
////4. Important step for using SQLite Cache
108-
//services.AddSQLiteCache(option =>
109-
//{
110-
// option.DBConfig = new SQLiteDBOptions { FileName="my.db" };
111-
//});
112-
113-
//services.AddSQLiteCache(Configuration);
114-
115-
////5. Important step for using Hybrid Cache
116-
////5.1. Local Cache
117-
//services.AddDefaultInMemoryCache(x=>
118-
//{
119-
// x.Order = 1;
120-
//});
121-
////5.2 Distributed Cache
122-
//services.AddDefaultRedisCache(option =>
123-
//{
124-
// option.Order = 2;
125-
// option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
126-
// option.DBConfig.Password = "";
127-
//});
128-
////5.3 Hybrid
129-
//services.AddDefaultHybridCache();
130-
}
131-
132-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
133-
{
134-
//2. Memcache Cache
135-
//app.UseDefaultMemcached();
136-
137-
//4. SQLite Cache
138-
//app.UseSQLiteCache();
139-
}
88+
//services.AddDefaultInMemoryCache(Configuration);
89+
}
14090
}
14191
```
14292

@@ -179,6 +129,54 @@ public class ValuesController : Controller
179129
}
180130
```
181131

132+
## Advanced Usages
133+
134+
### Multiple instances for single provider
135+
136+
After v0.4.0, EasyCaching import `IEasyCachingProviderFactory` to create providers by users.
137+
138+
Configure in `Startup.cs` at first.
139+
140+
```cs
141+
public void ConfigureServices(IServiceCollection services)
142+
{
143+
services.AddDefaultRedisCacheWithFactory("redis1",option =>
144+
{
145+
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
146+
});
147+
148+
services.AddDefaultRedisCacheWithFactory("redis2", option =>
149+
{
150+
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
151+
});
152+
}
153+
```
154+
Use `IEasyCachingProviderFactory` to create the provider.
155+
156+
```cs
157+
private readonly IEasyCachingProviderFactory _factory;
158+
159+
public CusController(IEasyCachingProviderFactory factory)
160+
{
161+
this._factory = factory;
162+
}
163+
164+
[HttpGet]
165+
[Route("")]
166+
public string GetRedis()
167+
{
168+
//use 6379
169+
var provider1 = _factory.GetCachingProvider("redis1");
170+
var val1 = provider1.Get("named-provider-1", () => "redis1", TimeSpan.FromMinutes(1));
171+
172+
//use 6380
173+
var provider2 = _factory.GetCachingProvider("redis2");
174+
var val2 = provider2.Get("named-provider-2", () => "redis2", TimeSpan.FromMinutes(1));
175+
176+
return $"OK";
177+
}
178+
```
179+
182180
## Documentation
183181

184182
For more helpful information about EasyCaching, please click [here](http://easycaching.readthedocs.io/en/latest/) for EasyCaching's documentation.

0 commit comments

Comments
 (0)