@@ -9,10 +9,10 @@ EasyCaching is an open source caching library that contains basic usages and som
9
9
10
10
## CI Build Status
11
11
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 ) |
16
16
17
17
## Nuget Packages
18
18
@@ -53,7 +53,7 @@ EasyCaching is an open source caching library that contains basic usages and som
53
53
|--------------| ------- | ----
54
54
| EasyCaching.ResponseCaching | ![ ] ( https://img.shields.io/nuget/v/EasyCaching.ResponseCaching.svg ) | ![ ] ( https://img.shields.io/nuget/dt/EasyCaching.ResponseCaching.svg )
55
55
56
- ## Basci Usages
56
+ ## Basic Usages
57
57
58
58
### Step 1 : Install the package
59
59
@@ -70,7 +70,7 @@ Install-Package EasyCaching.Memcached
70
70
71
71
Different types of caching hvae their own way to config.
72
72
73
- Here are samples show you how to config.
73
+ Here is a sample show you how to config.
74
74
75
75
``` csharp
76
76
public class Startup
@@ -81,62 +81,12 @@ public class Startup
81
81
{
82
82
services .AddMvc ();
83
83
84
- // 1. In-Memory Cache
84
+ // In-Memory Cache
85
85
services .AddDefaultInMemoryCache ();
86
86
87
87
// 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
+ }
140
90
}
141
91
```
142
92
@@ -179,6 +129,54 @@ public class ValuesController : Controller
179
129
}
180
130
```
181
131
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
+
182
180
## Documentation
183
181
184
182
For more helpful information about EasyCaching, please click [ here] ( http://easycaching.readthedocs.io/en/latest/ ) for EasyCaching's documentation.
0 commit comments