定时执行更新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. 函数def

    函数:把执行一定功能的动作封装到一起>>> def 函数名(形参)      通过一个    函数名(实参)         去调用它,传参来执行功能.动作,输出结果 .定义:def ...

  2. SVN忽略不提交文件夹

    eclipse提交经常要同步后再提交或更新,但是这时有很多不需要提交的文件.文件夹比较碍事,这时候就可以在svn上设置不需要关注的文件夹: 1.windows->preferences-> ...

  3. 大数据开发认知--spark

    1. Spark rdd生成过程· Spark的任务调度分为四步 1RDD objects RDD的准备阶段,组织RDD及RDD的依赖关系生成大概的RDD的DAG图,DAG图是有向环图. 2DAG s ...

  4. VS2010下安装boost库

    在我们的C++项目中安装boost库,下面以VS2010版本作为例子,其它版本的设置也差不多. 一.编译生成boost库 1.下载最新的boost(本人下载的是boost_1_56_0).boost官 ...

  5. Hybrid App 开发模式

    开发移动App主要有三种模式:Native. Hybrid 和 Web App. 需要注意的一点是在选择开发模式的时候,要根据你的项目类型(图片类?视频类?新闻类?等),产品业务和人员技术储备等做权衡 ...

  6. vue 学习笔记(一)

    对于 vue 官网给的教程由浅及深,非常容易上手.我之前有过 react 项目开发经验,对 webpack 打包,脚手架这一类的东西并不陌生.所以也是我上手比较快的原因吧.简单将我在学习 vue 中遇 ...

  7. Android人脸识别Demo竖屏YUV方向调整和图片保存

    本博客包含三个常用方法,用于盛开Android版人脸识别Demo中竖屏使用时送入yuv数据,但一直无法识别的情况. 1.首先可以尝试顺时针旋转90°或270°,然后送入识别SDK. 2.旋转方向后依然 ...

  8. Aspose.Words的Merge Field

    今天应客户要求,修改导出word模板.使用的是Aspose.Words插件.这个程序原是同事所写,且自己对Aspose不是很了解.在替换模板上花费了一些时间. 先来一张图:下图是原来的模板.现在要求删 ...

  9. English trip V2 - 3. A Healthy Diet Teacher:Corrine Key:各种前缀 im- un- in- re- over- under-

    In this lesson you will learn to talk about foot and drink for a healthy diet. 课上内容(Lesson) What do ...

  10. (桥接)完美解决linux设置静态ip。

    网上找来找去都是一些隔靴挠痒的操作,这里引自https://blog.csdn.net/yefeng0810/article/details/81150605.感谢大佬的博客.