System.Runtime.Caching;

using System;
using System.Collections.Generic;
using System.Runtime.Caching;

namespace EnterpriseLibraryCacheTest
{
    
public partial class WebForm1 : System.Web.UI.Page
    {
        
protected void Page_Load(object sender, EventArgs e)
        {
            
if (!IsPostBack)
            {
                TestCache();
            }
        }

        
protected void TestCache()
        {
            
//set cache
            ObjectCache cache = MemoryCache.Default;

            
//add cache
            List<string> listQuery = new List<string>
            {
                
"1","2"
            };
            CacheItemPolicy policy 
= new CacheItemPolicy();
            policy.SlidingExpiration 
= TimeSpan.FromMinutes(60);
            cache.Set(
"myCache", listQuery, policy);

            
//get cache
            List<string> listResult = (List<string>)cache["myCache"];
            
foreach (string ary in listResult)
            {
                Response.Write(ary);
            }
        }
    }


posted @ 2010-06-01 16:55  leeolevis  阅读(888)  评论(0编辑  收藏  举报