EasyCaching项目的第三方扩展:Autofac、WebApiClient、CAP、Microsoft.Extensions.Caching IDistributedCache
PM> Install-Package YrinLeung.EasyCaching.Bus.CAP
支持 netstandard2.0
Startup相关配置
public void ConfigureServices(IServiceCollection services)
{
//use EasyCaching
services.AddEasyCaching(option =>
{
// local
option.UseInMemory("m1");
// distributed
option.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379));
config.DBConfig.Database = 5;
}, "myredis");
// combine local and distributed
option.UseHybrid(config =>
{
config.TopicName = "test-topic";
config.EnableLogging = false;
config.LocalCacheProviderName = "m1";
config.DistributedCacheProviderName = "myredis";
});
// use CAP bus
option.WithCapBus(x =>
{
x.TopicName = "test-topic";
});
});
//use CAP ,根据CAP官方文档配置即可
services.AddCap(x =>
{
x.UseInMemoryStorage();
x.UseRabbitMQ(configure =>
{
configure.HostName = "127.0.0.1";
configure.UserName = "admin";
configure.Password = "admin";
});
x.UseDashboard();
});
...
}
查看 Demo
PM> Install-Package YrinLeung.EasyCaching.Interceptor.WebApiClient
支持 netstandard2.0
Startup相关配置
public void ConfigureServices(IServiceCollection services)
{
//将WebClient接口注入
services.AddWebApiClientUseHttpClientFactory<IWebApiClientService>();
//or
// services.AddWebApiClientUseHttpClientFactory<IWebApiClientService>((httpApiConfig) =>
// {
// httpApiConfig.HttpHost = new Uri("http://www.baidu.com");
// });
//or
// services.AddWebApiClientUseHttpClientFactory<IWebApiClientService>((httpApiConfig, p) =>
// {
// httpApiConfig.HttpHost = new Uri("http://www.baidu.com");
// });
...
}
查看 Demo
PM> Install-Package YrinLeung.EasyCaching.Interceptor.AspectCore.Autofac
支持 netstandard2.0
Startup相关配置
public void ConfigureContainer(ContainerBuilder builder)
{
//将AspectCore加入Autofac
builder.AddAspectCoreInterceptor(x => x.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName);
}
查看 Demo
PM> Install-Package YrinLeung.EasyCaching.Interceptor.Castle.Autofac
支持 netstandard2.0
Startup相关配置
public void ConfigureContainer(ContainerBuilder builder)
{
//将Castle加入Autofac
builder.AddCastleInterceptor(x => x.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName);
}
查看 Demo
PM> Install-Package YrinLeung.Microsoft.Extensions.Caching.EasyCaching
支持 netstandard2.0
Startup相关配置
public void ConfigureServices(IServiceCollection services)
{
services.AddEasyCachingCache(config =>
{
//EasyCaching的CachingProvider的Name
config.CachingProviderName = "DefaultRedis";
//默认滑动过期时间,默认20分钟
config.DefaultSlidingExpiration = TimeSpan.FromMinutes(20);
});
}
查看 Demo