定时执行更新Redis缓存操作

protected void Application_Start(object sender, EventArgs e)
{Timer timer = new Timer();timer.Enabled = true;timer.Interval = 3600000; //执行间隔时间,单位为毫秒; 这里实际间隔为1小时
    timer.Start();timer.Elapsed += new System.Timers.ElapsedEventHandler(OrgCacheInterval);
}/// <summary>
/// 定时检测组织机构缓存是否需要更新
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public void OrgCacheInterval(object source, ElapsedEventArgs e)
{ SystemService ser = new SystemService();ser.OrgCacheInterval();
}

/// <summary>
/// 组织机构缓存定时更新
/// </summary>
public void OrgCacheInterval()
{//不存在组织机构缓存或者时间戳时,更新if (!RedisCacheHelper.Exists("OrgList") || !RedisCacheHelper.Exists("OrgList:Time")){UpdateAllOrgCache();}//存在时间戳时判断时间是否一致,不一致时更新else{//缓存时间戳string cacheTime = RedisCacheHelper.Get<string>("OrgList:Time");//数据库更新缓存时间string modifyTime = OrgDb.GetKeyLastModifyTime("OrgList", "");//时间戳标记不一致时更新if (cacheTime != modifyTime){UpdateAllOrgCache();}}
}

/// <summary>
/// 获取键值更新时间
/// </summary>
/// <param name="db_key"></param>
/// <param name="lang_type"></param>
/// <returns></returns>
public string GetKeyLastModifyTime(string db_key, string lang_type)
{string time = string.Empty;try{string sql = string.Format(@"select * from sys_dbcache_time t where 1=1 and t.db_key='{0}' ", db_key);if (!string.IsNullOrEmpty(lang_type)){sql += string.Format(@" and t.lang_type='{0}' ", lang_type);}DataTable dt = OdpOracleHelper.Query(sql).Tables[0];if (dt != null && dt.Rows.Count > 0){time = Convert.ToDateTime(dt.Rows[0]["op_modify_time"]).ToString("yyyy-MM-dd HH:mm:ss");}else{string _time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");string insertSql = string.Format(@"insert into sys_dbcache_time(db_key,lang_type,op_modify_time)                             values('{0}','{1}',to_date('{2}','yyyy-MM-dd HH24:MI:SS'))", db_key, lang_type, _time);OdpOracleHelper.ExecuteSql(insertSql);time = _time;}}catch (Exception ex){throw ex;}return time;
}

转载于:https://www.cnblogs.com/Jackie-sky/p/10276986.html

C# Global.asax.cs 定时任务相关推荐

  1. Global.asax.cs中的方法(包括自定义方法)的含义

    跟Request有关的放到后面一起说,先说其他的5个. Application_Init:在每一个HttpApplication实例初始化的时候执行. Application_Disposed:在每一 ...

  2. 运行mvc项目报错 %@ Application Codebehind=Global.asax.cs Inherits=NHAPPAPI.MvcApplication Language=C...

    当运行项目报如下错误时,检查网站生成目录是否含有特殊符号或空格 <%@ Application Codebehind="Global.asax.cs" Inherits=&q ...

  3. ASP.NET 调试出现%@ Application Codebehind=Global.asax.cs Inherits=XXX.XXX.Global Language=C# %...

    ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global&q ...

  4. %@ Application Codebehind=Global.asax.cs Inherits=XXX.MvcApplication Language=C# %

    <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...

  5. %@ Application Codebehind=Global.asax.cs Inherits=FS.JYPEIS.WeCharReserve.WebApiApplication Lan

    直接开门见山 错误如下: 在网上找到如下原因: 1.项目命名空间  检查项目命名空间 包括Global.asax.app_start下.controllers等文件夹下,命名空间是否与项目名称一致(至 ...

  6. 行 1: %@ Application Codebehind=Global.asax.cs Inherits=FuceFP.Web.Global Language=C# %

    之前为了避免typescript编译出错把项目文件typescripttoolversion节点注释掉了,结果导致项目启动不了.把注释打开就行了. <TypeScriptToolsVersion ...

  7. Global.asax详解

    在网上找了N多相关的东西总说的不够细,现在终于找到了.可以了解web.cofig和Global.asax之间的关系以及执行的顺序. 在Global.asax.cs文件中 protected void ...

  8. global.asax不执行原因

    之前用windows服务做了个定时服务,出了点问题就换成用global.asax做定时任务. 刚开始用vs调试能进入Application_Start方法,但是发布到IIS上就不行了. 这是因为调试的 ...

  9. asp.net(C#)网站发布后 Global.asax 里 Application_Error 不执行的问题

    现象 在 Global.asax 用 Application_Error 捕捉了http的404,500等错误,在本机测试正常,发布后无效,几经周折终于解决了... 程序是这样设计的 Applicat ...

最新文章

  1. python asyncio与aiohttp_python链家网异步IO爬虫,使用asyncio、aiohttp和aiomysql
  2. webpack初学笔记 之 小案例篇demo1
  3. monkey测试_安卓测试之monkey
  4. 一个短小精悍的在线jshint工具
  5. 微信红包系统架构的设计和优化分享
  6. 中国大妈也不带钱包了!支付宝春节60后境外支付人数增长130%
  7. VB 文件常用操作相关API
  8. 网络管理与维护作业6
  9. 如何在Excel中提取身份证号码中的信息
  10. 拆分工作簿为多个文件_能不能将总表快速拆分为多个工作簿?当然!
  11. 基于互联网的摄像测量系统(D 题)-- 2021 年全国大学生电子设计竞赛
  12. hashmap java 排序_HashMap的排序
  13. Android 自定义歌词滚动
  14. 关键链项目管理汇总贴
  15. 怎样查看自己的电脑是多少位的?
  16. 有效学习的6个方法学习方法
  17. 这5个“计算机专业”就业很吃香,毕业生需求量大,还不会过时
  18. hint ksql oracle_性能测试中发现oracle11g数据库每天22点,oralce进程CPU占用率突增
  19. 查询IP信息接口罗列
  20. cerr与cout心得

热门文章

  1. 使用mysql事件_MySQL事件的使用详解
  2. git指令快捷 idea_IDEA+Git+Gitlab使用详细教程
  3. APP技巧:手机连接WiFi后,移动数据流量要不要关闭,看完你就懂了!
  4. IDEA高级技巧:集成JIRA、UML类图插件、SSH、FTP、Database管理
  5. Java 类在 Tomcat 中是如何加载的?
  6. 批量保存到mysql_关于保存批量数据进入mysql
  7. 【LeetCode】整数反转
  8. java例子:数组 数3退1
  9. flutter 透明度动画_Flutter中的动画填充+不透明度动画✨
  10. 如何优雅处理 async await 错误——解读小而美的 await-to-js 库