开张了

  终于在博客园开了空间,意味着,再也不用在Sohu Blog里粘代码了

  先粘两段爽一下:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Web.Caching;
using System.Text;

using IndieCommon;
using IndieORM;
using IndieDB;
using IndieLogic;

/// <summary>
/// Vote 获取当前调查
/// 的投票选项统计结果
/// </summary>

[WebService(Namespace = "http://localhost/")]
[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
public class Vote : System.Web.Services.WebService
{

    
public Vote()
    
{
        
        
//如果使用设计的组件,请取消注释以下行 
        
//InitializeComponent(); 
    }


    [WebMethod]
    
public string GetVoteStatus()
    
{
        
// 缓存的键名
        string key = "CurrInvest";
        
// 存储
        addInvestToCache(key);

        
// 从缓存中获取
        Invest invest = (Invest)HttpContext.Current.Cache[key];

        
返回结果
    }


    
/// <summary>
    
/// 缓存被删除回调方法
    
/// </summary>
    
/// <param name="key"></param>
    
/// <param name="value"></param>
    
/// <param name="reason">原因</param>

    private void removalCallBack(string key, object value, CacheItemRemovedReason reason)
    
{
        
// SQL依赖项被改变
        if (reason == CacheItemRemovedReason.DependencyChanged)
        
{
            
// 投票项被删除
            if (key == "CurrInvest")
            
{
                addInvestToCache(
"CurrInvest");
            }

        }

    }


    
/// <summary>
    
/// 在缓存中插入最近一期INVEST对象
    
/// </summary>
    
/// <param name="key"></param>

    private void addInvestToCache(string key)
    
{
        
// 调查操作对象
        InvestOperation io = new InvestOperation();

        
// 进行数据缓存
        if (HttpContext.Current.Cache[key] == null)
        
{
            
// 获取当前期调查            
            Invest currInvest = io.GetLastInvest();

            
if (currInvest != null)
            
{
                
// 数据库和表名
                string datatabase = "Indie";
                
string tablename = "TB_INVEST";
                SqlCacheDependency dependency 
= new SqlCacheDependency(datatabase,tablename);
                
// 回调
                CacheItemRemovedCallback removal = new CacheItemRemovedCallback(removalCallBack);

                
// SQL SERVER 依赖轮询缓存
                HttpContext.Current.Cache.Insert("CurrInvest", currInvest, dependency
                    ,DateTime.MaxValue,Cache.NoSlidingExpiration,CacheItemPriority.Normal,
                    removal);
            }

        }

    }

}



 

原文地址:https://www.cnblogs.com/moye/p/815602.html