コード例 #1
0
        /// <summary>
        /// 取得采集器的年月数据对象,经过缓存
        /// </summary>
        /// <param name="collectorID"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public CollectorYearMonthData GetCollectorYearMonthData(int collectorID, int year)
        {
            string cacheKey = CacheKeyUtil.buildCollectorEnergyYearCountKey(collectorID,year);
            object obj = MemcachedClientSatat.getInstance().Get(cacheKey);

            CollectorYearMonthData deviceYearMonthData;
            if (obj == null)
            {//从数据库中取得
                deviceYearMonthData = _plantYearDataDao.GetCollectorYearMonthData(collectorID, year);
                if (deviceYearMonthData == null)//构造一个新实例
                    deviceYearMonthData = new CollectorYearMonthData() {  year = year, collectorID =collectorID};
                deviceYearMonthData.localAcceptTime = DateTime.Now;
                MemcachedClientSatat.getInstance().Set(cacheKey, deviceYearMonthData);
            }
            else
                deviceYearMonthData = (CollectorYearMonthData)obj;

            return deviceYearMonthData;
        }
コード例 #2
0
        /// <summary>
        /// 将各个月度数据付给map
        /// </summary>
        /// <param name="monthDataMap"></param>
        /// <param name="unitYearData"></param>
        private void putMonthMap(Hashtable monthDataMap, CollectorYearMonthData yearData)
        {
            string yyyy = yearData.year.ToString();
            for (int i = 1; i <= 12; i++)
            {
                string key = yyyy + TableUtil.convertIntToMnthStr(i);
                System.Object obj = monthDataMap[key];

                object tmpvalue = yearData.GetType().GetProperty("m_" + i).GetValue(yearData, null);
                float value = tmpvalue == null ? 0 : StringUtil.stringtoFloat(tmpvalue.ToString());
                if (obj != null || tmpvalue != null)
                    monthDataMap[key] = (obj == null ? 0 : StringUtil.stringtoFloat(obj.ToString())) + value;
            }
        }
コード例 #3
0
        /// <summary>
        /// 放入缓存
        /// </summary>
        /// <param name="collectorYearMonthData"></param>
        public void Cache(CollectorYearMonthData collectorYearMonthData)
        {
            string cacheKey = CacheKeyUtil.buildCollectorEnergyYearCountKey(collectorYearMonthData.collectorID, collectorYearMonthData.year);

            if (!persistentListKey.Contains(cacheKey)) persistentListKey.Add(cacheKey);
            //一年3天后过期
            MemcachedClientSatat.getInstance().Set(cacheKey, collectorYearMonthData, DateTime.Now.AddYears(1).AddDays(3));
        }