-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from dotnetcore/dev
Named Caching Provider
- Loading branch information
Showing
36 changed files
with
1,444 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sample/EasyCaching.Demo.Providers/Controllers/CusController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace EasyCaching.Demo.Providers.Controllers | ||
{ | ||
using EasyCaching.Core; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
|
||
[Route("api/[controller]")] | ||
public class CusController : Controller | ||
{ | ||
private readonly IEasyCachingProviderFactory _factory; | ||
|
||
public CusController(IEasyCachingProviderFactory factory) | ||
{ | ||
this._factory = factory; | ||
} | ||
|
||
// GET api/cus/inmem?name=Default | ||
[HttpGet] | ||
[Route("inmem")] | ||
public string Get(string name = EasyCachingConstValue.DefaultInMemoryName) | ||
{ | ||
var provider = _factory.GetCachingProvider(name); | ||
var val = name.Equals("cus") ? "cus" : "default"; | ||
var res = provider.Get("demo", () => val, TimeSpan.FromMinutes(1)); | ||
return $"cached value : {res}"; | ||
} | ||
|
||
// GET api/cus/redis?name=Default | ||
[HttpGet] | ||
[Route("redis")] | ||
public string GetRedis(string name = EasyCachingConstValue.DefaultRedisName) | ||
{ | ||
var provider = _factory.GetCachingProvider(name); | ||
var val = name.Equals("redis1") ? $"redis1-{Guid.NewGuid()}" : $"redis2-{Guid.NewGuid()}"; | ||
var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1)); | ||
return $"cached value : {res}"; | ||
} | ||
|
||
|
||
// GET api/cus/com?name=Default | ||
[HttpGet] | ||
[Route("com")] | ||
public string GetCom(string name = "cus") | ||
{ | ||
var provider = _factory.GetCachingProvider(name); | ||
var val = $"{name}-{Guid.NewGuid()}"; | ||
var res = provider.Get("named-provider2", () => val, TimeSpan.FromMinutes(1)); | ||
return $"cached value : {res}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.