zoukankan      html  css  js  c++  java
  • 缓存

    一、通过数据库的sysdate字段

    public class CacheData
    {

    /// <summary>
    /// 字典集合
    /// </summary>
    private static Dictionary<string, DataTable> dicStuData = new Dictionary<string, DataTable>()// <summary>

    /// 根据班级查找班级学生信息
    /// </summary>
    /// <returns></returns>
    public static DataTable GetStuInfoByName(string name)
    {
    DataTable dt=null;
    //次日清空
    if (dicStuData .TryGetValue(name, out dt)&&dt.Rows.Count>0)
    {
    DateTime cacheTime = Convert.ToDateTime(dt.Rows[0]["sysdate"]);
    //缓存一天
    if (cacheTime.Date != DateTime.Now.Date)
    {
    dicStuData [name] = null;
    }
    }

    if (dt == null|| dt.Rows.Count == 0)
    {
    //查询学生信息
    string sql = @"select  distinct  stuname,stuNo, address , sysdate from classInfo
    where classname ='{0}'";
    try
    {

    //查询数据库
    dt=dicStuData [name] = DBContext.GetDataTable(sql);
    }
    catch (Exception ex)
    {

    //记录错误日志
    Log.Error("根据班级名:["+name+"],查询学生信息异常:", ex);
    }
    }
    return dt;
    }

    }

  • 相关阅读:
    CSS Modules
    回调地狱
    css实现双色饼图
    vue项目中使用less
    pug(jade) 学习笔记
    React组件proptypes, ref
    react+express实现跨域
    react高阶组件
    Oracle数据库出现锁表情况分析
    JPA常用注解记录
  • 原文地址:https://www.cnblogs.com/LeiYang5237/p/7500324.html
Copyright © 2011-2022 走看看