zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    OS-lab4
    OS-lab3
    OS-lab2
    OS-lab1
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    HTTP_POST
    实习日志1(2020.7.27-2020.9.31)
    Web app ------ 从Servlet读取Json数据并显示,生成历史数据曲线图
  • 原文地址:https://www.cnblogs.com/simhare/p/851271.html
Copyright © 2011-2022 走看看