惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - sonicit

再写Javascript闭包 C# 使用 Newtonsoft.Json 对DataTable转换中文乱码问题的解决 Vue 数据双向绑定的误区 关于JS Pormise的认识 关于jqGrid中GridUnload方法的困惑 Javascript异步编程的4种方法 SQLServer 获得所有表结构(包括表名及字段) ACE代码编辑器,代码提示,添加自定义数据 利用闭包向post回调函数传参数 在seajs中使用require加载静态文件的问题 jqGrid标题行与第一行之间有很大空白的问题解决。 关于bootstrapValidator提交问题的解决 心得(一) 使用心得(一) MSSQL获得表的字段名称及其参数 Controller_Abstract的改造 QeePHP View视图的默认变量与新增变量 Delphi 的内存操作函数(5): 复制内存 Windows 7 安装VS2008 SP1 失败
后台数据缓存的一点心得
sonicit · 2021-12-10 · via 博客园 - sonicit

最近在实际使用中发现,当IIS应用程序池自动回收后,此时访问页面,会提示 “未将对象引用设置到对象的实例”的错误,查看代码发现,使用了类中的静态变量。

public static List<ReportData> = new List<ReportData>();

单看这个问题不大,因为此变量在类中,应用程序池回收后,因为类本身不是static,且不能变为static,所以要加以改造。

使用类单例模式,就可以比较好的解决这一问题。

因为类单例模式,在运行时实例唯一,这是做缓存的根本。

    public class EMPDataInterfaceDataCacheO : EMPDataCacheO
    {
        /// <summary>
        /// 数据接口中缓存类
        /// </summary>
        public class ListData : CacheListData { }
        /// <summary>
        /// 超时时间,3分钟
        /// </summary>
        private const int OverTime = 3;
        /// <summary>
        /// 缓存列表
        /// </summary>
        private List<ListData> cacheList;
        /// <summary>
        /// EMPDataInterfaceDataCache 实例
        /// </summary>
        private static EMPDataInterfaceDataCacheO cache;
        /// <summary>
        /// 获得缓存实例
        /// </summary>
        /// <returns>实例</returns>
        public static EMPDataInterfaceDataCacheO GetInstance()
        {
            if (cache == null)
            {
                cache = new EMPDataInterfaceDataCacheO();
            }
            return cache;
        }

        private EMPDataInterfaceDataCacheO()
        {
            cacheList = new List<ListData>();
        }
    }

以上是部分代码,类中实现了,缓存数据的存取,过期的自动清理等。