コード例 #1
0
 /// <summary>
 /// 获取文档并重置到期时提供的给定值。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="expiration"></param>
 /// <returns></returns>
 public T GetAndTouch <T>(string key, TimeSpan expiration)
 {
     try
     {
         var result = _bucket.GetAndTouch <T>(key, expiration);
         return(result.Success ? result.Value : default(T));
     }
     catch (Exception ex)
     {
         throw new Exception($"CouchBase GetAndTouch Operate Error,Message:{ex.Message}", ex);
     }
 }
コード例 #2
0
        public void When_GetAndTouch_Is_Called_Expiration_Is_Extended()
        {
            var key = "When_GetAndTouch_Is_Called_Expiration_Is_Extended";

            _bucket.Remove(key);
            _bucket.Insert(key, "{value}", new TimeSpan(0, 0, 0, 2));
            Thread.Sleep(3000);
            var result = _bucket.Get <string>(key);

            Assert.AreEqual(result.Status, ResponseStatus.KeyNotFound);
            _bucket.Remove(key);
            _bucket.Insert(key, "{value}", new TimeSpan(0, 0, 0, 2));
            result = _bucket.GetAndTouch <string>(key, new TimeSpan(0, 0, 0, 5));
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Value, "{value}");
            Thread.Sleep(3000);
            result = _bucket.Get <string>(key);
            Assert.AreEqual(result.Status, ResponseStatus.Success);
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="newExpiration"></param>
 /// <returns></returns>
 public T Get <T>(string key, DateTime newExpiration) where T : class
 {
     return(_bucket.GetAndTouch <T>(key, newExpiration - DateTime.Now).Value);
 }