///// <summary> ///// 获取指定委托的缓存数据,如果该缓存不存在,则自动调用数据源委托生成缓存 ///// </summary> ///// <typeparam name="T">缓存数据的类型</typeparam> ///// <param name="cacheTime">缓存时间</param> ///// <param name="callback">数据源委托</param> ///// <returns></returns> //public static T Get<T>(CacheTimeOption cacheTime, Expression<RefreshCacheDataHandler> callback) where T : class //{ // MethodCallExpression exp = callback.Body as MethodCallExpression; // StringBuilder sbKey = new StringBuilder(); // sbKey.Append("AUTO_CACHE_KEY___"); // sbKey.Append(exp.Method.DeclaringType.FullName); // sbKey.Append("_"); // sbKey.Append(exp.Method.Name); // for (int i = 0; i < exp.Arguments.Count; i++) // { // sbKey.Append("_"); // if (exp.Arguments[i] is ConstantExpression) // { // sbKey.Append((exp.Arguments[i] as ConstantExpression).Value); // } // if (exp.Arguments[i] is MemberExpression) // { // sbKey.Append((exp.Arguments[i] as MemberExpression).Member); //方法变量参数的值取法有问题,需要复杂运算,暂时搁浅。。 // } // } // string key = ""; // if (Contains(key)) // { // return Get<T>(key); // } // T content = callback.Compile()() as T; // Set<T>(key, content, cacheTime); // return content; //} /// <summary> /// 获取指定key缓存数据,如果该缓存不存在,则自动调用数据源委托生成缓存 /// </summary> /// <typeparam name="T">缓存数据的类型</typeparam> /// <param name="key">缓存key</param> /// <param name="cacheTime">缓存时间</param> /// <param name="callback">数据源委托</param> /// <param name="removedCallback">缓存失效时的回调函数</param> /// <returns></returns> public static T Get <T>(string key, CacheTimeOption cacheTime, RefreshCacheDataHandler <T> callback, CacheItemRemovedCallback removedCallback) where T : class { // 不缓存时,直接返回 if (cacheTime == CacheTimeOption.None) { return(callback()); } if (Contains(key)) { return(Get <T>(key)); } T content = callback(); Set(key, content, cacheTime, removedCallback); return(content); }
public List <LinkTagCount> GetTagCountCache( DateTime begin, DateTime end, int softid, int platform, net91com.Stat.Core.PeriodOptions period, int version, int tagid, string tagText, bool isCategory, CacheTimeOption cachetime) { string cacheKey = BuildCacheKey("GetTagCountCache", begin, end, softid, platform, period, version, tagid, isCategory); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <LinkTagCount> >(cacheKey).ToList()); } List <LinkTagCount> list = LinkTagLog_DataAccess.Instance.GetTagCountList( begin, end, (int)period, softid, platform, version, tagid, tagText, isCategory); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <LinkTagCount> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); }
public DateTime GetMaxTimeCache(net91com.Stat.Core.PeriodOptions period, ReportType Type, CacheTimeOption cachetime, string otherKeyString = "") { if (useCache == true) { string cacheKey = BuildCacheKey("GetMaxTimeCache", period, Type, otherKeyString); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(new DateTime(CacheHelper.Get <DateTime>(cacheKey).Ticks)); } DateTime list = GetMaxTime(period, Type, otherKeyString); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <DateTime>(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(new DateTime(list.Ticks)); } else { return(GetMaxTime(period, Type, otherKeyString)); } }
public List <SoftUser> GetUsersWithNoPeriodCache(DateTime begin, DateTime end, int softid, int platformid, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetUsersWithNoPeriodCache", begin, end, softid, platformid); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <SoftUser> >(cacheKey)); } List <SoftUser> list = GetSoftUsersNoPeriod(begin, end, softid, platformid); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <SoftUser> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetSoftUsersNoPeriod(begin, end, softid, platformid)); } }
/// <summary> /// 共用的用户留存量 /// </summary> /// <param name="softId"></param> /// <param name="platform"></param> /// <param name="channelId"></param> /// <param name="period"></param> /// <param name="fromDate"></param> /// <param name="toDate"></param> /// <param name="cachetime"></param> /// <returns></returns> public List <Sjqd_StatChannelRetainedUsers> GetStatRetainedUsersCache(int softId, int platform, int channelId, net91com.Stat.Core.PeriodOptions period, DateTime fromDate, DateTime toDate, CacheTimeOption cachetime, ChannelTypeOptions channelType, URLoginService loginService) { if (useCache == true) { string cacheKey = BuildCacheKey("GetStatRetainedUsersCache", softId, platform, channelId, period, fromDate, toDate, channelType, loginService == null ? "" : ((loginService.LoginUser.AccountType == Reports.UserRights.UserTypeOptions.Channel || loginService.LoginUser.AccountType == Reports.UserRights.UserTypeOptions.ChannelPartner) ? loginService.LoginUser.ID.ToString() : "")); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Sjqd_StatChannelRetainedUsers> >(cacheKey).ToList()); } List <Sjqd_StatChannelRetainedUsers> list = GetStatRetainedUsers(softId, platform, channelId, period, fromDate, toDate, channelType, loginService); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Sjqd_StatChannelRetainedUsers> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list.ToList()); } else { return(GetStatRetainedUsers(softId, platform, channelId, period, fromDate, toDate, channelType, loginService)); } }
/// <summary> /// 获取对应所选渠道下的,所有用户信息 /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <param name="softid"></param> /// <param name="platformid"></param> /// <param name="period"></param> /// <param name="selectchanneltype"></param> /// <param name="selectchannelvalue"></param> /// <param name="cachetime"></param> /// <returns></returns> public List <SoftUser> GetSoftUserChanelListCache(DateTime begin, DateTime end, int softid, int platformid, net91com.Stat.Core.PeriodOptions period, ChannelTypeOptions selectchanneltype, int selectchannelvalue, string channleName, bool useModules, net91com.Reports.UserRights.URLoginService loginService, CacheTimeOption cachetime) { string cacheKey = BuildCacheKey("GetSoftUserChanelListCache", begin, end, softid, platformid, period, selectchanneltype, selectchannelvalue, useModules, loginService == null ? "" : ((loginService.LoginUser.AccountType == UserTypeOptions.Channel || loginService.LoginUser.AccountType == UserTypeOptions.ChannelPartner) ? loginService.LoginUser.ID.ToString() : "")); return(CacheHelper.Get <List <SoftUser> >(cacheKey, CacheTimeOption.TenMinutes, () => GetSoftUserChanelList(begin, end, softid, platformid, period, selectchanneltype, selectchannelvalue, channleName, useModules, loginService))); }
public DateTime GetMinTimeCache(int softid, int platformid, ReportType Type, DateTime begintime, DateTime endtime, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetMinTimeCache", softid, platformid, Type, begintime, endtime); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(new DateTime(CacheHelper.Get <DateTime>(cacheKey).Ticks)); } DateTime list = GetMinTime(softid, platformid, Type, begintime, endtime); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <DateTime>(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(new DateTime(list.Ticks)); } else { return(GetMinTime(softid, platformid, Type, begintime, endtime)); } }
public List <Sjqd_StatLifecycle> GetSoftLifeCycleCache(int softid, int platformid, DateTime date, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetSoftLifeCycleCache", softid, platformid, date); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Sjqd_StatLifecycle> >(cacheKey).Clone().ToList()); } List <Sjqd_StatLifecycle> list = GetSoftLifeCycle(softid, platformid, date); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Sjqd_StatLifecycle> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list.Clone().ToList()); } else { return(GetSoftLifeCycle(softid, platformid, date)); } }
public List <Sjqd_StatUsers> GetSimpleSoftUserListCache(DateTime begin, net91com.Stat.Core.PeriodOptions period, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetSimpleSoftUserListCache", begin, period); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Sjqd_StatUsers> >(cacheKey).ToList()); } List <Sjqd_StatUsers> list = GetSimpleSoftUserList(begin, period); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Sjqd_StatUsers> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetSimpleSoftUserList(begin, period)); } }
public List <Monitor_DataLogs> GetLogTransverseCache(string dataLogName, DateTime begintime, DateTime endtime, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetLogTransverseCache", dataLogName, begintime, endtime); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Monitor_DataLogs> >(cacheKey).ToList()); } List <Monitor_DataLogs> list = GetLogTransverse(dataLogName, begintime, endtime); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Monitor_DataLogs> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetLogTransverse(dataLogName, begintime, endtime)); } }
/// <summary> /// 获取版本信息 /// </summary> /// <param name="softid"></param> /// <param name="platformid"></param> /// <param name="cachetime"></param> /// <returns></returns> public List <SoftVersion> GetVersionCacheStatDB(int softid, int platformid, int versiontype, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetVersionCacheStatDB", softid, platformid, versiontype); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <SoftVersion> >(cacheKey)); } List <SoftVersion> list = GetVersion(softid, platformid, versiontype); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <SoftVersion> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetVersion(softid, platformid, versiontype)); } }
/// <summary> /// 设置下次调用该接口的任意方法时的缓存时间 /// </summary> /// <param name="cacheTime">缓存时间</param> public void SetCacheTime(CacheTimeOption cacheTime) { _cacheTime = cacheTime; }
public List <ForecastSoftUser> GetForecastSoftUserCache(int softid, int platformid, PeriodOptions period, URLoginService loginService, CacheTimeOption cachetime) { string cacheKey = BuildCacheKey("GetForecastSoftUserCache", softid, platformid, period, loginService == null ? "" : ((loginService.LoginUser.AccountType == UserTypeOptions.Channel || loginService.LoginUser.AccountType == UserTypeOptions.ChannelPartner) ? loginService.LoginUser.ID.ToString(): "")); return(CacheHelper.Get <List <ForecastSoftUser> >(cacheKey, CacheTimeOption.TenMinutes, () => GetForecastSoftUser(softid, platformid, period, loginService))); }
/// <summary> /// 获取指定key缓存数据,如果该缓存不存在,则自动调用数据源委托生成缓存(线程安全,但会造成一定性能开销) /// </summary> /// <typeparam name="T">缓存数据的类型</typeparam> /// <param name="key">缓存key</param> /// <param name="recordCountKey">记录总数的缓存key</param> /// <param name="recordCount">记录总数(out)</param> /// <param name="cacheTime">缓存时间</param> /// <param name="callback">数据源委托</param> /// <returns></returns> public static T GetWithLock <T>(string key, string recordCountKey, out int recordCount, CacheTimeOption cacheTime, RefreshCacheDataWithOutParamHandler <T> callback) where T : class { // 不缓存时,直接返回 if (cacheTime == CacheTimeOption.None) { return(callback(out recordCount)); } recordCount = 0; if (Contains(recordCountKey)) { recordCount = Get <int>(recordCountKey); } if (Contains(key)) { return(Get <T>(key)); } lock (string.Intern(key)) { if (Contains(recordCountKey)) { recordCount = Get <int>(recordCountKey); } if (Contains(key)) { return(Get <T>(key)); } else { T content = callback(out recordCount); Set(key, content, cacheTime); Set(recordCountKey, recordCount, cacheTime); return(content); } } }
/// <summary> /// 获取指定key缓存数据,如果该缓存不存在,则自动调用数据源委托生成缓存 /// </summary> /// <typeparam name="T">缓存数据的类型</typeparam> /// <param name="key">缓存key</param> /// <param name="recordCountKey">记录总数的缓存key</param> /// <param name="recordCountKey2">记录总数的缓存key2</param> /// <param name="recordCount">记录总数(ref)</param> /// <param name="recordCount2">记录总数2(ref)</param> /// <param name="cacheTime">缓存时间</param> /// <param name="callback">数据源委托</param> /// <returns></returns> public static T Get <T>(string key, string recordCountKey, string recordCountKey2, ref int recordCount, ref int recordCount2, CacheTimeOption cacheTime, RefreshCacheDataWithRefParamHandler2 <T> callback) where T : class { // 不缓存时,直接返回 if (cacheTime == CacheTimeOption.None) { return(callback(ref recordCount, ref recordCount2)); } if (Contains(recordCountKey)) { recordCount = Get <int>(recordCountKey); } if (Contains(recordCountKey2)) { recordCount2 = Get <int>(recordCountKey2); } if (Contains(key) && recordCount != 0 && recordCount2 != 0) { return(Get <T>(key)); } T content = callback(ref recordCount, ref recordCount2); Set(key, content, cacheTime); Set(recordCountKey, recordCount, cacheTime); Set(recordCountKey2, recordCount2, cacheTime); return(content); }
/// <summary> /// 添加缓存(如果缓存键已经存在,则此方法调用无效) /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="key">缓存键</param> /// <param name="value">值</param> /// <param name="CacheTimeOption">缓存时间</param> public static void Set <T>(string key, T value, CacheTimeOption CacheTimeOption) { Set(key, value, CacheTimeOption, CacheExpirationOption.AbsoluteExpiration, null, CacheItemPriority.NotRemovable, null); }
/// <summary> /// 添加缓存(如果缓存键已经存在,则此方法调用无效) /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="key">缓存键</param> /// <param name="value">值</param> /// <param name="CacheTimeOption">缓存时间</param> /// <param name="CacheExpirationOption">缓存过期时间类别(绝对/弹性)</param> /// <param name="dependencies">缓存依赖项</param> public static void Set <T>(string key, T value, CacheTimeOption CacheTimeOption, CacheExpirationOption CacheExpirationOption, CacheDependency dependencies) { Set(key, value, CacheTimeOption, CacheExpirationOption, dependencies, CacheItemPriority.NotRemovable, null); }
public List <SoftUser> GetSoftUserListCache(DateTime begin, DateTime end, int softid, int platformid, PeriodOptions period, URLoginService loginService, CacheTimeOption cachetime) { string cacheKey = BuildCacheKey("GetSoftUserListCache", begin, end, softid, platformid, period, ((loginService.LoginUser.AccountType == UserTypeOptions.Channel || loginService.LoginUser.AccountType == UserTypeOptions.ChannelPartner)? loginService.LoginUser.ID.ToString(): "")); return(CacheHelper.Get <List <SoftUser> >(cacheKey, CacheTimeOption.TenMinutes, () => GetSoftUserList(begin, end, softid, platformid, period, loginService))); }
///获取历史最值 public List <SoftUser> GetMaxNumCache(DateTime begin, DateTime end, int softid, int platformid, net91com.Stat.Core.PeriodOptions period, CacheTimeOption cachetime) { string cacheKey = BuildCacheKey("GetMaxNumCache", begin, end, softid, platformid, period); return(CacheHelper.Get <List <SoftUser> >(cacheKey, CacheTimeOption.TenMinutes, () => GetMaxNum(begin, end, softid, platformid, period))); }
public DateTime GetMaxChannelUserTimeCache(int softid, MobileOption plat, net91com.Stat.Core.PeriodOptions period, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetMaxChannelUserTimeCache", softid, plat, period); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(new DateTime(CacheHelper.Get <DateTime>(cacheKey).Ticks)); } DateTime list = GetMaxChannelUserTime(softid, plat, period); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <DateTime>(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(new DateTime(list.Ticks)); } else { return(GetMaxChannelUserTime(softid, plat, period)); } }
public List <Sjqd_ULSessionsSingle> GetSingleULSessionsLengthCache(int softid, int platform, string version, int period, DateTime begintime, DateTime endtime, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetSingleULSessionsLengthCache", softid, platform, version, period, begintime, endtime); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Sjqd_ULSessionsSingle> >(cacheKey).ToList()); } List <Sjqd_ULSessionsSingle> list = GetSingleULSessionsLength(softid, platform, version, period, begintime, endtime); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Sjqd_ULSessionsSingle> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetSingleULSessionsLength(softid, platform, version, period, begintime, endtime)); } }
public List <Sjqd_StatUsersByMAC> GetTop100MacUsersByCache(int softId, MobileOption platform, net91com.Stat.Core.PeriodOptions period, DateTime statdate, CacheTimeOption cachetime) { if (useCache == true) { string cacheKey = BuildCacheKey("GetTop100MacUsersByCache", softId, platform, period, statdate); if (CacheHelper.Contains(cacheKey) && cachetime != CacheTimeOption.None) { return(CacheHelper.Get <List <Sjqd_StatUsersByMAC> >(cacheKey)); } List <Sjqd_StatUsersByMAC> list = GetTop100MacUsers(softId, platform, period, statdate); if (list != null && cachetime != CacheTimeOption.None) { CacheHelper.Set <List <Sjqd_StatUsersByMAC> >(cacheKey, list, cachetime, CacheExpirationOption.AbsoluteExpiration); } return(list); } else { return(GetTop100MacUsers(softId, platform, period, statdate)); } }