winfrom中使用cache

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Threading;


namespace NPao.Tools.EntityDesign
{
    
public class CacheConfig
    
{
        
private static HttpRuntime _httpRuntime;

        
public static Cache Cache
        
{
            
get
            
{
                EnsureHttpRuntime();
                
return HttpRuntime.Cache;
            }

        }


        
private static void EnsureHttpRuntime()
        
{
            
if (null == _httpRuntime)
            
{
                
try
                
{
                    Monitor.Enter(
typeof(CacheConfig));
                    
if (null == _httpRuntime)
                    
{
                        
// Create an Http Content to give us access to the cache.
                        _httpRuntime = new HttpRuntime();
                    }

                }

                
finally
                
{
                    Monitor.Exit(
typeof(CacheConfig));
                }

            }

        }


    }

}


使用:
string s = CacheConfig.Cache["txt"] as string;
            if (!string.IsNullOrEmpty(s))
                MessageBox.Show(s);
            else
                CacheConfig.Cache.Insert("txt",txtConnStr.Text);

posted on 2008-04-06 19:42 隨風.NET 阅读(46) 评论(0)  编辑 收藏


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 
另存  打印
 


导航

公告

希望自己能静心写点blog,很多内容来自与互联网,如果没有添加来源,可能是忘记了,还请谅解
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

统计

与我联系

常用链接

留言簿

我管理的小组

我参与的团队

随笔分类(5)

随笔档案(27)

links

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

60天内阅读排行