about Cache

 protected void Page_Load(object sender, EventArgs e)
    
{
        
decimal amzn = (decimal)Cache["amzn"];
        
//Object objAmzn = (object)amzn;
        Response.Write(amzn);
    }

    
protected void Page_Init(object sender, EventArgs e)
    
{
        
//Cache.Insert("amzn", 10.00m);
        Cache["amzn"= 30.00m;
    }

Global.asax
<%@ Application Language="C#"  %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
    
static Cache _cache;
    
static string _path;
    
void Application_Start(object sender, EventArgs e) 
    
{
        
// Code that runs on application startup
        _cache = Context.Cache;
        _path 
= Server.MapPath("Stocks.xml");
        DataSet ds 
= new DataSet();
        ds.ReadXml(_path);
        _cache.Insert(
"Stocks", ds, new CacheDependency(_path), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, new CacheItemRemovedCallback(RefreshDataSet));
        
    }

    
static void RefreshDataSet(string key, Object item, CacheItemRemovedReason reason)
    
{
        DataSet ds 
= new DataSet();
        ds.ReadXml(_path);
        _cache.Insert(
"Stocks", ds, new CacheDependency(_path), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, new CacheItemRemovedCallback(RefreshDataSet));
    }
 
 
    
    
void Application_End(object sender, EventArgs e) 
    
{
        
//  Code that runs on application shutdown

    }

        
    
void Application_Error(object sender, EventArgs e) 
    

        
// Code that runs when an unhandled error occurs

    }


    
void Session_Start(object sender, EventArgs e) 
    
{
        
// Code that runs when a new session is started

    }


    
void Session_End(object sender, EventArgs e) 
    
{
        
// Code that runs when a session ends. 
        
// Note: The Session_End event is raised only when the sessionstate mode
        
// is set to InProc in the Web.config file. If session mode is set to StateServer 
        
// or SQLServer, the event is not raised.

    }

       
</script>

posted on 2007-08-10 21:18  simhare  阅读(365)  评论(0编辑  收藏  举报

导航