public RpanAccessToken getAvaliableAccessToken() { var sysConfig = _memoryCache.GetOrCreate(CConstants.MemoryKey_SysConfig, a => { a.SetAbsoluteExpiration(TimeSpan.FromDays(90)); return(_systemRepository.GetByKey("ContentCenter").Result); }); RpanAccessToken result = new RpanAccessToken(); panAccessToken panAccessToken = _memoryCache.Get <panAccessToken>(CConstants.MemoryKey_BaiduPanAccessToken); if (panAccessToken == null) { panAccessToken = _baiduPanRepository.getAvaliableAccessToken(); if (panAccessToken == null) { return(result); } _memoryCache.Set(CConstants.MemoryKey_BaiduPanAccessToken, panAccessToken, TimeSpan.FromHours(1)); } //现在时间和创建AccessToken时间差 int consumDay = ToolUtil.DateDiff(DateTime.Now, panAccessToken.createDateTime); int remainDay = sysConfig.baiduPanTokenExpiredDay - consumDay; if (remainDay <= 0) { _baiduPanRepository.expireAllAccessToken(); _memoryCache.Remove(CConstants.MemoryKey_BaiduPanAccessToken); } else { result.remainDay = remainDay; result.panAccessToken = panAccessToken; } return(result); }