private void updateCacheConsumedMessage(long count, DateTime utcNow) { _messageConsumedCount = count; _redisCacheHelper.SetKeyValue(_cachekey_message_total_consumed_count, count.ToString()); //_consoleLog.Info("Redis Cache {0} is {1}", _cachekey_message_total_consumed_count.ToString(), count); _messageConsumedDate = utcNow; _redisCacheHelper.SetKeyValue(_cachekey_message_consumed_date, utcNow.ToString("yyyy-MM-ddTHH:mm:ss.fff")); //_consoleLog.Info("Redis Cache {0} was updated {1}", _cachekey_message_consumed_date.ToString(), utcNow.ToString("yyyy-MM-ddTHH:mm:ss.fff")); }
public IHttpActionResult GetRolesByEmployeeId(int id) { RedisKey cacheKey = "employee_" + id + "_Role"; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { using (var ctx = new SFDatabaseEntities()) { var roles = ctx.EmployeeInRole .Where(s => s.EmployeeID == id && s.DeletedFlag == false) .Select(s => new EmployeeRoleModels.Detail() { UserRoleId = s.UserRoleID, UserRoleName = s.UserRole.Name }).ToList <EmployeeRoleModels.Detail>(); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(roles)); return(Ok(roles)); } } else { return(Ok(new JavaScriptSerializer().Deserialize <List <Object> >(cacheValue))); } }
public IHttpActionResult GetCompanyById() { int companyId = GetCompanyIdFromToken(); RedisKey cacheKey = "external_company_" + companyId; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { CompanyModels companyModel = new CompanyModels(); try { CompanyModels.Detail_readonly company = companyModel.getCompanyByIdReadonly(Convert.ToInt32(companyId.ToString())); RedisCacheHelper.SetKeyValue(cacheKey, JsonConvert.SerializeObject(company)); return(Ok(company)); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); string logAPI = "[Get] " + Request.RequestUri.ToString(); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError()); } } else { return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue))); } }
public IHttpActionResult GetAllDeviceTypes() { string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (string.IsNullOrEmpty(cacheValue) || cacheValue.Length < 10) { DeviceTypeModels deviceTypeModel = new Models.DeviceTypeModels(); List <DeviceTypeModels.Detail> deviceTypeList = deviceTypeModel.GetAllDeviceType(); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(deviceTypeList)); return(Ok(deviceTypeList)); } else { return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue))); } }
public IHttpActionResult GetPermissionsByEmployeeId(int id) { RedisKey cacheKey = "employee_" + id + "_Permission"; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { EmployeeModels employeeModel = new EmployeeModels(); var empPermissions = employeeModel.GetAllPermissionById(id); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(empPermissions)); return(Ok(empPermissions)); } else { return(Ok(new JavaScriptSerializer().Deserialize <List <Object> >(cacheValue))); } }
public IHttpActionResult GetCompanyById(int id) { RedisKey cacheKey = "company_" + id; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { CompanyModels companyModel = new CompanyModels(); try { CompanyModels.Detail company = companyModel.getCompanyById(id); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(company)); return(Ok(company)); } catch { return(NotFound()); } } else { return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue))); } }
public IHttpActionResult GetEmployeeById(int id) { RedisKey cacheKey = "employee_" + id; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { EmployeeModels employeeMode = new EmployeeModels(); try { var employee = employeeMode.GetEmployeeById(id); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(employee)); return(Ok(employee)); } catch { return(NotFound()); } } else { return(Ok(new JavaScriptSerializer().Deserialize <Object>(cacheValue))); } }
public IHttpActionResult GetAll() { RedisKey cacheKey = "cultureCodesJson"; string cacheValue = RedisCacheHelper.GetValueByKey(cacheKey); if (cacheValue == null) { using (var ctx = new SFDatabaseEntities()) { var cultureCodes = ctx.RefCultureInfo .Select(s => new RefCultureInfoModels() { CultureCode = s.CultureCode, Name = s.Name }).ToList <RefCultureInfoModels>(); RedisCacheHelper.SetKeyValue(cacheKey, new JavaScriptSerializer().Serialize(cultureCodes)); return(Ok(cultureCodes)); } } else { return(Ok(new JavaScriptSerializer().Deserialize <List <RefCultureInfoModels> >(cacheValue))); } }