public void Can_increment_and_decrement_values()
        {
            Assert.That(Cache.Increment("incr:a", 2), Is.EqualTo(2));
            Assert.That(Cache.Increment("incr:a", 3), Is.EqualTo(5));

            Assert.That(Cache.Decrement("decr:a", 2), Is.EqualTo(-2));
            Assert.That(Cache.Decrement("decr:a", 3), Is.EqualTo(-5));
        }
        public void DyanmoDb_ExerciseCacheClient()
        {
            // Expecting the Set operation to succeed
            bool setResponse = _client.Set <DummyObject>(_itemCacheKey, _item);

            Assert.AreEqual(true, setResponse);

            // Expecting the Get to return the item cached above
            var actual = _client.Get <DummyObject>(_itemCacheKey);

            Assert.IsNotNull(actual);
            Assert.AreEqual(_item.UserId, actual.UserId);

            // Expecting Add to return false since the item is already cached
            bool addResponse = _client.Add <DummyObject>(_itemCacheKey, _item);

            Assert.AreEqual(false, addResponse);

            // Expecting remove to succeed
            bool removeResponse = _client.Remove(_itemCacheKey);

            Assert.AreEqual(true, removeResponse);

            // Add the item back, expecting success
            addResponse = _client.Add <DummyObject>(_itemCacheKey, _item);
            Assert.AreEqual(true, addResponse);

            // Remove it again
            removeResponse = _client.Remove(_itemCacheKey);

            // Clear the counter if it exists
            removeResponse = _client.Remove(_counterCacheKey);

            // Initialize the counter, incResponse should be equal to 0 since the counter doesn't exist
            long incResponse = _client.Increment(_counterCacheKey, 0);

            // Increment by 1
            long updatedIncResponse = _client.Increment(_counterCacheKey, 1);

            Assert.AreEqual(incResponse + 1, updatedIncResponse);
            // Decrement by 1
            long decResponse = _client.Decrement(_counterCacheKey, 1);

            Assert.AreEqual(incResponse, decResponse);

            // Clear out the cache - this will cause a very long delete/re-create DynamoDB table sequence
            _client.FlushAll();
        }
 public long Decrement(string key, uint amount)
 {
     return(cache.Decrement(prefix + key, amount));
 }
 public long Decrement(string key, uint amount)
 {
     return(cache.Decrement(EnsurePrefix(key), amount));
 }
Beispiel #5
0
 public long Decrement(string key, uint amount)
 {
     return(cacheClient.Decrement(key, amount));
 }