zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    MySQL主从复制搭建
    CSS基本样式简单介绍
    前端代码编码规范
    Markdown语法简单介绍
    Java API 操作Redis
    Java API 操作Zookeeper
    MySQL优化
    ES 可视化工具
    消息队列MQ
    Docker基础
  • 原文地址:https://www.cnblogs.com/xinzhyu/p/1139413.html
Copyright © 2011-2022 走看看