我对 HttpCache 和 Singleton 方法的理解有点困惑。
我的应用程序使用 Asp.net MVC,场景是,我有一些永远不会改变的数据列表和一些可能很少改变的数据。
我已经为此类数据使用 Singleton 存储库开发和部署了应用程序。它表现出色。唯一的问题是,当发生罕见的情况时,我必须重新启动 IIS 才能生效。
什么是最好的解决方案。?
单例实现
public class SingletonRepository : ISingletonRepository
{
private static SingletonRepository singleInstance;
private readonly IStateRepository stateRepo;
private readonly ICountryRepository countryRepo;
private readonly ITDPaymentModeRepository paymentModeRepo;
private readonly ITDPlanRepository planRepo;
private readonly ITDOrderTypeRepository orderTypeRepo;
private readonly IKeywordRepository keywordRepo;
private readonly IAgencyRepository agencyRepo;
private readonly IList<AT_STATE> lstState;
private readonly IList<AT_COUNTRY> lstCountry;
private readonly IList<TDPaymentMode> lstPaymentMode;
private readonly IList<TDPlan> lstPlan;
private readonly IList<TDOrderType> lstOrderType;
private readonly IList<Keyword> lstKeyword;
private readonly IList<Agency_MST> lstAgency;
private SingletonRepository()
{
stateRepo = new StateRepository();
countryRepo = new CountryRepository();
paymentModeRepo = new TDPaymentModeRepository();
planRepo = new TDPlanRepository();
orderTypeRepo = new TDOrderTypeRepository();
keywordRepo = new KeywordRepository();
agencyRepo = new AgencyRepository();
lstState = stateRepo.GetAll().Where(x => x.CountryId == 101).ToList();
lstCountry = countryRepo.GetAll().ToList();
lstPaymentMode = paymentModeRepo.GetAll().ToList();
lstPlan = planRepo.GetAll().ToList();
lstOrderType = orderTypeRepo.GetAll().ToList();
lstKeyword = keywordRepo.GetAll().ToList();
lstAgency = agencyRepo.GetAll().ToList();
//lstState = stateRepo.GetAll().Take(20).ToList();
//lstCountry = countryRepo.GetAll().Take(20).ToList();
//lstPaymentMode = paymentModeRepo.GetAll().Take(20).ToList();
//lstPlan = planRepo.GetAll().Take(20).ToList();
//lstOrderType = orderTypeRepo.GetAll().Take(20).ToList();
//lstKeyword = keywordRepo.GetAll().Take(20).ToList();
//lstAgency = agencyRepo.GetAll().Take(20).ToList();
}
public static SingletonRepository Instance()
{
return singleInstance ?? (singleInstance = new SingletonRepository());
}
public IList<AT_STATE> GetState()
{
return this.lstState;
}
public IList<AT_COUNTRY> GetCountry()
{
return this.lstCountry;
}
public IList<TDPaymentMode> GetPaymentMode()
{
return this.lstPaymentMode;
}
public IList<TDPlan> GetPlan()
{
return this.lstPlan;
}
public IList<TDOrderType> GetOrderType()
{
return this.lstOrderType;
}
public IList<Keyword> GetKeyword()
{
return this.lstKeyword;
}
public IList<Agency_MST> GetAgency()
{
return this.lstAgency;
}
}
}