开张了
2007-07-12 15:35 莫耶 阅读(372) 评论(2) 编辑 收藏 举报 终于在博客园开了空间,意味着,再也不用在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);
}
}
}
}
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);
}
}
}
}
本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议
欢迎转载,但必须保留文章的署名老莫的帐本子
并保留此链接:http://moye.cnblogs.com/
如有疑问请发邮件:moyerock@gmail.com
欢迎转载,但必须保留文章的署名老莫的帐本子
并保留此链接:http://moye.cnblogs.com/
如有疑问请发邮件:moyerock@gmail.com