EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
Platform | Build Server | Master Status | Dev Status |
---|---|---|---|
AppVeyor | Windows/Linux | ||
Travis | Linux/OSX |
Package Name | Version | Downloads |
---|---|---|
EasyCaching.Core |
Package Name | Version | Downloads |
---|---|---|
EasyCaching.InMemory | ||
EasyCaching.Redis | ||
EasyCaching.Memcached | ||
EasyCaching.SQLite | ||
EasyCaching.HybridCache |
Package Name | Version | Downloads |
---|---|---|
EasyCaching.Interceptor.Castle | ||
EasyCaching.Interceptor.AspectCore |
Package Name | Version | Downloads |
---|---|---|
EasyCaching.Serialization.MessagePack | ||
EasyCaching.Serialization.Json | ||
EasyCaching.Serialization.Protobuf |
Package Name | Version | Downloads |
---|---|---|
EasyCaching.ResponseCaching |
Choose one kinds of caching type that you needs and install it via Nuget.
Install-Package EasyCaching.InMemory
Install-Package EasyCaching.Redis
Install-Package EasyCaching.SQLite
Install-Package EasyCaching.Memcached
Different types of caching hvae their own way to config.
Here is a sample show you how to config.
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
//In-Memory Cache
services.AddDefaultInMemoryCache();
//Read from appsetting.json
//services.AddDefaultInMemoryCache(Configuration);
}
}
[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly IEasyCachingProvider _provider;
public ValuesController(IEasyCachingProvider provider)
{
this._provider = provider;
}
[HttpGet]
public string Get()
{
//Set
_provider.Set("demo", "123", TimeSpan.FromMinutes(1));
//Set Async
await _provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1));
//Get without data retriever
var res = _provider.Get<string>("demo");
//Get without data retriever Async
var res = await _provider.GetAsync<string>("demo");
//Get
var res = _provider.Get("demo", () => "456", TimeSpan.FromMinutes(1));
//Get Async
var res = await _provider.GetAsync("demo",async () => await Task.FromResult("456"), TimeSpan.FromMinutes(1));
//others ....
}
}
After v0.4.0, EasyCaching import IEasyCachingProviderFactory
to create providers by users.
Configure in Startup.cs
at first.
public void ConfigureServices(IServiceCollection services)
{
services.AddDefaultRedisCacheWithFactory("redis1",option =>
{
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
});
services.AddDefaultRedisCacheWithFactory("redis2", option =>
{
option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
});
}
Use IEasyCachingProviderFactory
to create the provider.
private readonly IEasyCachingProviderFactory _factory;
public CusController(IEasyCachingProviderFactory factory)
{
this._factory = factory;
}
[HttpGet]
[Route("")]
public string GetRedis()
{
//use 6379
var provider1 = _factory.GetCachingProvider("redis1");
var val1 = provider1.Get("named-provider-1", () => "redis1", TimeSpan.FromMinutes(1));
//use 6380
var provider2 = _factory.GetCachingProvider("redis2");
var val2 = provider2.Get("named-provider-2", () => "redis2", TimeSpan.FromMinutes(1));
return $"OK";
}
For more helpful information about EasyCaching, please click here for EasyCaching's documentation.
See sample
- Memory
- Redis
- SQLite
- Memcached
- Hybrid(Combine local caching and distributed caching)
- Disk
- Others...
- Get/GetAsync(with data retriever)
- Get/GetAsync(without data retriever)
- Set/SetAsync
- Remove/RemoveAsync
- Refresh/RefreshAsync
- RemoveByPrefix/RemoveByPrefixAsync
- SetAll/SetAllAsync
- GetAll/GetAllAsync
- GetByPrefix/GetByPrefixAsync
- RemoveAll/RemoveAllAsync
- GetCount
- Flush/FlushAsync
- Others...
- BinaryFormatter
- MessagePack
- Json
- ProtoBuf
- Others...
- AspectCore
- Castle
- Others ..
- EasyCachingAble
- EasyCachingPut
- EasyCachingEvict
Note: Not support Hybird Caching provider yet.
- Redis
- RabbitMQ
- Configuration
- Caching Region
- Caching Statistics
- UI Manager
- Logger
- Caching Warm Up
- ...
Pull requests, issues and commentary!