コード例 #1
0
        /// <summary>
        /// 追加或修改缓冲对象
        /// </summary>
        /// <param name="uniqueKey"></param>
        /// <param name="value"></param>
        /// <returns>返回执行完修改操作后,缓冲区中对应的数据</returns>
        public bool AddOrUpdate(string uniqueKey, BufferEntry value)
        {
            CacheItemPolicy policy = GetPolicy();

            _buffer.Set(uniqueKey, value, policy);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 从缓存区中创建或者获取数据
        /// </summary>
        /// <param name="tip"></param>
        /// <param name="getCacheKey"></param>
        /// <param name="dataVersion"></param>
        /// <param name="load"></param>
        /// <returns></returns>
        private IAggregateRoot GetOrCreateImpl(string uniqueKey, int dataVersion, Func <IAggregateRoot> load)
        {
            BufferEntry result = null;

            if (_buffer.TryGet(uniqueKey, out result))
            {
                if (result.DataVersion == dataVersion)
                {
                    return(result.Root);
                }
            }

            //更新缓冲区
            var root = load();

            result = new BufferEntry(root);
            _buffer.AddOrUpdate(uniqueKey, result);
            return(result.Root);
        }
コード例 #3
0
        private void Add(string uniqueKey, IAggregateRoot root)
        {
            var result = new BufferEntry(root); //主动追加的数据,版本号从1开始

            _buffer.AddOrUpdate(uniqueKey, result);
        }
コード例 #4
0
 /// <summary>
 /// 尝试从缓冲区中获取数据
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool TryGet(string uniqueKey, out BufferEntry value)
 {
     value = _buffer[uniqueKey] as BufferEntry;
     return(value != null);
 }