缓存组件
缓存组件可以对接redis或内存方式,支持事件触发更新缓存。
App.config
<redisconfig configSource="XmlConfig\redis.config" />
<?xml version="1.0" encoding="utf-8"?>
<redisconfig WriteServerList="127.0.0.1:6379" ReadServerList="127.0.0.1:6379" MaxWritePoolSize="60" MaxReadPoolSize="60" AutoStart="true" LocalCacheTime="180" RecordeLog="false"></redisconfig>
主函数调用缓存组件
调用Autofac注入依赖方式调用缓存
#region Cache
public static Autofac.IContainer _container;
public static Caching.ICacheManager _cacheManager;
//private ISignals _signals;
public static IRedisSignals _redisSignals;
/// <summary>
/// Key for model changed
/// </summary>
public static readonly string ONLINEMTLS_SIGNAL_CHANGED = "aabb.onlineMtls.changed";
public static readonly string ONLINEMTLS_QUERY_KEY = "aabb.onlineMtls-LineId-{0}";
#endregion
public void InitCache()
{
var builder = new ContainerBuilder();
builder.RegisterModule(new CacheModule());
builder.RegisterType<DefaultCacheManager>().Named<ICacheManager>("RedisCacheManager")
.WithParameters(new[] {
new ResolvedParameter((pi, i) => pi.ParameterType == typeof(Type),
(pi, i) => GetType()),
new ResolvedParameter((pi, i) => pi.ParameterType == typeof(ICacheHolder),
(pi, i) => i.ResolveNamed<ICacheHolder>("RedisCache"))
}).SingleInstance();
builder.RegisterType<RedisCacheHolder>().Named<ICacheHolder>("RedisCache").As<ICacheHolder>().SingleInstance();
//builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().SingleInstance();
builder.RegisterType<DefaultCacheContextAccessor>().As<ICacheContextAccessor>().SingleInstance();
//builder.RegisterType<DefaultParallelCacheContext>().As<IParallelCacheContext>().SingleInstance();
//builder.RegisterType<DefaultAsyncTokenProvider>().As<IAsyncTokenProvider>().SingleInstance();
RegisterVolatileProvider<RedisSignals, IRedisSignals>(builder);
//RegisterVolatileProvider<Signals, ISignals>(builder);
_container = builder.Build();
_cacheManager = _container.Resolve<ICacheManager>(new TypedParameter(typeof(Type), GetType()));
//_signals = _container.Resolve<ISignals>();
_redisSignals = _container.Resolve<IRedisSignals>();
}
private void RegisterVolatileProvider<TRegister, TService>(ContainerBuilder builder) where TService : IVolatileProvider
{
builder.RegisterType<TRegister>()
.As<TService>()
.As<IVolatileProvider>()
.SingleInstance();
}