Selector/Selector.Cache/Consumer/Factory/CacheWriterFactory.cs

38 lines
933 B
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
namespace Selector.Cache
{
public interface ICacheWriterFactory {
public Task<IConsumer> Get(IPlayerWatcher watcher = null);
}
public class CacheWriterFactory: ICacheWriterFactory {
private readonly ILoggerFactory LoggerFactory;
private readonly IDatabaseAsync Cache;
public CacheWriterFactory(
IDatabaseAsync cache,
ILoggerFactory loggerFactory
) {
Cache = cache;
LoggerFactory = loggerFactory;
}
public async Task<IConsumer> Get(IPlayerWatcher watcher = null)
{
return new CacheWriter(
watcher,
Cache,
LoggerFactory.CreateLogger<CacheWriter>()
);
}
}
}