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  阅读(371)  评论(0编辑  收藏  举报

导航