定时执行更新Redis缓存操作

protected void Application_Start(object sender, EventArgs e)
{
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = ; //执行间隔时间,单位为毫秒; 这里实际间隔为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[];
if (dt != null && dt.Rows.Count > )
{
time = Convert.ToDateTime(dt.Rows[]["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;
}

C# Global.asax.cs 定时任务的更多相关文章

  1. Where is the Global.asax.cs file

    I am using VS 2008. I have created a new Asp.net web site project from File->New->Website-> ...

  2. 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 ...

  3. <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>

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

  4. Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer

    x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...

  5. Global.asax.cs介绍

    转载  http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...

  6. Global.asax.cs中相关方法

    protected void Session_Start(object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protect ...

  7. .Global.asax.cs中的方法的含义

    Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...

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

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

  9. ASP.NET Global.asax详解

    最近在研究bbsmax的代码,但是一直不知道入口在哪里,然后就对各个文件分析了,然后终于在对global.asax文件查看的时候看到Application_BeginRequest才明白入口,所以现在 ...

随机推荐

  1. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  2. jenkins 启动被杀死

    1.重设环境变量build_id 在execute shell输入框中加入BUILD_ID=DONTKILLME,即可防止jenkins杀死启动的tomcat进程 2.在启动jenkins 的时候禁止 ...

  3. Mac 虚拟打印机PDFWriter on Sierra

    之前就装过PdfWriter,第一次装的时候失败了,后来在app store 装了PDF Printer,好像挺好用的,但是升级有点贵.又回去研究了一下PDFWriter. 和PDFWriter在so ...

  4. redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

    $ pip install redis>>> import redis>>> conn = redis.Redis()>>> conn.keys( ...

  5. Http 状态码:

    消息 100 Continue 101 Switching Protocols 102 Processing 成功 200 OK 201 Created 202 Accepted 203 Non-Au ...

  6. Struts 2 框架搭建HelloWorld

    1.导包 导入相应的jar包,在blank项目中会出现 2.书写Action类 package com.littlepage.struts; public class HelloAction { pu ...

  7. nrf52832板子焊接后总结的经验

    将之前打的nrf52832的板子拿到手了,经过一番焊接和调试后,发现了一些问题,因为是第一次画板焊接调试,很多地方做的不好,现在将自己的一些经验总结如下: 1 在制板之前,丝印层有必要好好的检查,建议 ...

  8. linux 配置ftp服务

    需求:定时远程上传文件,windows->linux linux是一个云服务器,centos7 1:安装vsftpd yum install vsftpd 2:设置开机启动服务chkconfig ...

  9. 【转载】阻塞队列之三:SynchronousQueue同步队列 阻塞算法的3种实现

    一.SynchronousQueue简介 Java 6的并发编程包中的SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除 ...

  10. [GXOI/GZOI2019]旅行者

    就我感觉这道题很神仙吗/kel 仔细想想应该也是一种适用范围挺广的做法. 考虑我们可以通过dijkstra在O(nlogn)求出一个点集到另外一个点集的最短路. 那么我们可以通过一些划分点集的方式使得 ...