打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Page.Cache,HttpContext.Cache,HttpRuntime.Cache,Hashtable有什么区别,怎么用.

           今天终于看了一下CACHE ,一点学习心得与大家一起分享.也请大家指教.
Page.Cache,HttpContext.Cache,HttpRuntime.Cache,Hashtable有什么区别,怎么用.

   HttpContext.Cache,HttpRuntime.Cache,用法上没有区别,就是使用范围不同.  
   HttpContext.Cache是基于上下文,对同一个用户起做用,如果换了一个访问,那么这个CACHE就不起做用了.
   HttpRuntime.Cache是全局的,对任务人都有做,只要有内容,任务用户都可以访问.
   



    public class HttpRuntimeCache
    
{
    
        
public static string Instance()
        
{
            
string vc=(string)HttpRuntime.Cache["Test"];
            
if(vc==null)
            
{
                HttpRuntime.Cache.Add(
"Test","test"null,System.DateTime.Now.AddDays(10),TimeSpan.Zero,
                CacheItemPriority.Default,
null);
            }

            
return vc;
        }


    }


   Page.Cache实际上是访问其它CACHE的接口.可以通过Page.Cache来访问HttpContext.Cache,HttpRuntime.Cache里面的东西.

   还有另外一种保存Cache方式是,使用Hashtable等来保存,值的一说的是这种Cache也是全局 ,而且是不可过期的 ,我想这是与 HttpRuntime.Cache的一个区别吧.至于安全性能方面我还没有去验证.Hashtable保存方式比较特别,就是NEW的时候要使用同步关健字.



 1
public class hashcache
 2
    
{
 3
       
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
 4

 5
        
public static void CacheParameters(string cacheKey, string cmdParms) 
 6
        
{
 7
            parmCache[cacheKey] 
= cmdParms;
 8
        }

 9

10
        
public static string GetCachedParameters(string cacheKey) 
11
        
{
12
            
return (string)parmCache[cacheKey];
13
        }

14
    }


    
       

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# 数据缓存操作Cache
ASP.NET缓存全解析4:应用程序数据缓存
DataCache - 李的日志 - 网易博客
.net中Cache依赖数据库应用
MVC4 Simplemembership实现用户权限管理
Asp.Net读取配置文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服