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 |
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)
{
//configuration
services.AddEasyCaching(option=>
{
//use memory cache that named default
option.UseInMemory("default");
//use redis cache that named redis1
option.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
}, "redis1")
.WithMessagePack()//with messagepack serialization
;
});
}
}
[Route("api/[controller]")]
public class ValuesController : Controller
{
// //when using single provider
// private readonly IEasyCachingProvider _provider;
//when using multiple provider
private readonly IEasyCachingProviderFactory _factory;
public ValuesController(
//IEasyCachingProvider provider,
IEasyCachingProviderFactory factory
)
{
//this._provider = provider;
this._factory = factory;
}
[HttpGet]
public string Handle()
{
//var provider = _provider;
//get the provider from factory with its name
var provider = _factory.GetCachingProvider("redis1");
//Set
provider.Set("demo", "123", TimeSpan.FromMinutes(1));
//Set Async
await provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1));
}
}
For more helpful information about EasyCaching, please click here for EasyCaching's documentation.
See sample
- Memory
- Redis(Based on StackExchange.Redis)
- Redis(Based on csredis)
- 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
- TrySet/TrySetAsync
- Others...
- BinaryFormatter
- MessagePack
- Json
- ProtoBuf
- Others...
- AspectCore
- Castle
- Others ..
- EasyCachingAble
- EasyCachingPut
- EasyCachingEvict
Note: Not support Hybird Caching provider yet.
- Redis (Based on StackExchange.Redis)
- Redis (Based on csredis)
- RabbitMQ
- Configuration
- Caching Region (one region with an instance of provider)
- Caching Statistics
- UI Manager
- Logger
- Caching Warm Up
- ...
Pull requests, issues and commentary!