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

推荐订阅源

S
SegmentFault 最新的问题
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Latest news
Latest news
I
Intezer
A
Arctic Wolf
IT之家
IT之家
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
AWS News Blog
AWS News Blog
博客园 - 三生石上(FineUI控件)
C
CXSECURITY Database RSS Feed - CXSecurity.com
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
B
Blog
博客园 - 叶小钗
V2EX - 技术
V2EX - 技术
Simon Willison's Weblog
Simon Willison's Weblog
MyScale Blog
MyScale Blog
Hugging Face - Blog
Hugging Face - Blog
Engineering at Meta
Engineering at Meta
NISL@THU
NISL@THU
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
The GitHub Blog
The GitHub Blog
V
V2EX
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
V
Visual Studio Blog
Vercel News
Vercel News
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
O
OpenAI News
爱范儿
爱范儿

博客园 - 早班火车

很还念这里。。。说些什么呢。。。 程序,好亲切~ IE与DOM下访问内联样式和外部样式表的常用方法总结 关于javascript中的事件学习及总结 总结了几个常用的sql server系统表的使用 在做一个小网站的一些心得与遇到的问题总结,为以后方便查阅。 用sql脚本一条条导数据的两种方法,需返回唯一标识@@IDENTITY作为插入到第二个表用。 一步一步教你抓数据——用.net精确提取网站数据的通用方法 也来为自己的博客加个花,兼AJAX跨域的一点疑问。 关于IE缓存和AJAX的一点思考和疑问 退一步海阔天空:抛开思维定势 DOCTYPE:你可能不知道的 我的2007--从2008做起,加油! javascript常用验证 正则表达式参考手册__Mini版 树的操作(绑定数据库,添加新节点,删除节点)(转载加实现) 一段好用的ajax和div漂浮显示效果实现 ajax小贴士 javascript操纵剪贴板
好用的缓存类
早班火车 · 2007-11-01 · via 博客园 - 早班火车

  1using System;
  2using System.Collections;
  3using System.Text.RegularExpressions;
  4using System.Web;
  5using System.Web.Caching;
  6
  7namespace ChetxNews.Function
  8{
  9    public class SiteCache
 10           
 11    {
 12        private static readonly Cache _cache;
 13        public static readonly int DayFactor;
 14        private static int Factor;
 15        public static readonly int HourFactor;
 16        public static readonly int MinuteFactor;
 17        
 18        static SiteCache()
 19        {
 20            DayFactor = 17280;
 21            HourFactor = 720;
 22            MinuteFactor = 12;
 23            Factor = 5;
 24            _cache = HttpRuntime.Cache;
 25        }

 26    
 27        private SiteCache()
 28        {
 29        }

 30    
 31        public static void Clear()
 32        {
 33            IDictionaryEnumerator enumerator = _cache.GetEnumerator();
 34            while (enumerator.MoveNext())
 35                
 36            {
 37                _cache.Remove(enumerator.Key.ToString());
 38            }

 39        }

 40    
 41        public static object Get(string key)
 42        {
 43            if(_cache[key] !=null)
 44            {
 45                return _cache[key];
 46            }

 47            else
 48            {
 49                return null;
 50            }

 51            
 52        }

 53
 54        public static void Insert(string key, object obj)
 55        {
 56            Insert(key, obj, null1);
 57        }

 58
 59        public static void Insert(string key, object obj, int seconds)
 60        {
 61            Insert(key, obj, null, seconds);
 62        }

 63
 64        public static void Insert(string key, object obj, CacheDependency dep)
 65        {
 66            Insert(key, obj, dep, HourFactor*12);
 67        }

 68
 69        public static void Insert(string key, object obj, int seconds, CacheItemPriority priority)
 70        {
 71            Insert(key, obj, null, seconds, priority);
 72        }

 73
 74        public static void Insert(string key, object obj, CacheDependency dep, int seconds)
 75        {
 76            Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
 77        }

 78
 79        public static void Insert(string key, object obj, CacheDependency dep, int seconds, CacheItemPriority priority)
 80        {
 81            if (obj != null)
 82            
 83            {
 84                _cache.Insert(key, obj, dep, DateTime.Now.AddSeconds((double) (Factor*seconds)), TimeSpan.Zero, priority, null);
 85            }

 86        }

 87
 88        public static void Max(string key, object obj)
 89        {
 90            Max(key, obj, null);
 91        }

 92
 93        public static void Max(string key, object obj, CacheDependency dep)
 94        {
 95            if (obj != null)
 96            
 97            {
 98                _cache.Insert(key, obj, dep, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.AboveNormal, null);
 99            }

100        }

101
102        public static void MicroInsert(string key, object obj, int secondFactor)
103        {
104            if (obj != null)
105            
106            {
107                _cache.Insert(key, obj, null, DateTime.Now.AddSeconds((double) (Factor*secondFactor)), TimeSpan.Zero);
108            }

109        }

110
111        public static void Remove(string key)
112        {
113            _cache.Remove(key);
114        }

115
116        public static void RemoveByPattern(string pattern)
117        {
118            IDictionaryEnumerator enumerator = _cache.GetEnumerator();
119            Regex regex1 = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
120            while (enumerator.MoveNext())
121           
122            {
123                if (regex1.IsMatch(enumerator.Key.ToString()))
124                
125                {
126                    _cache.Remove(enumerator.Key.ToString());
127                }

128            }

129        }

130
131        public static void ReSetFactor(int cacheFactor)
132        {
133            Factor = cacheFactor;
134        }

135    
136    }

137}

138