zoukankan      html  css  js  c++  java
  • 开张了

      终于在博客园开了空间,意味着,再也不用在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);
                }

            }

        }

    }



     

  • 相关阅读:
    深入理解yield from语法
    数据库事务并发问题,锁机制和对应的4种隔离级别
    同源策略与CORS跨域请求
    Restful 4 -- 认证组件、权限组件、频率组件、url注册器、响应器、分页器
    Restful 3 -- 序列化组件(GET/PUT/DELETE接口设计)、视图优化组件
    Restful 2 --DRF解析器,序列化组件使用(GET/POST接口设计)
    Restful 1 -- REST、DRF(View源码解读、APIView源码解读)及框架实现
    Vue(7)- vue-cookies、极验滑动验证geetest、vue-router的导航守卫
    Vue --6 router进阶、单页面应用(SPA)带来的问题
    Vue 5 -- axios、vuex
  • 原文地址:https://www.cnblogs.com/moye/p/815602.html
Copyright © 2011-2022 走看看