seamusabshere/cache

Handle differences in incrementing non-existing keys in the various implementations

Closed this issue · 1 comments

This project is a great idea, heard about it on The Ruby Show! I'm not too familiar with all the different stores but from what I gathered there's a difference in how they handle incrementing non-existing keys.

For example memcached-client returns nil when you try to increase an unknown key, whereas Dalli I think initializes the key with 0 if it doesn't exist yet (or was it the other way round?).

From what I've seen in the code this is not yet covered by cache so I wanted to point it out in case you're not aware yet.

hey,

I added test coverage to show how increment/decrement work in this gem:

def test_increment
  assert !@cache.exist?('high-fives')
  assert_equal 1, @cache.increment('high-fives')
  assert_equal 1, @cache.get('high-fives')
  assert_equal 2, @cache.increment('high-fives')
  assert_equal 2, @cache.get('high-fives')
end

def test_decrement
  assert !@cache.exist?('high-fives')
  assert_equal -1, @cache.decrement('high-fives')
  assert_equal -1, @cache.get('high-fives')
  assert_equal -2, @cache.decrement('high-fives')
  assert_equal -2, @cache.get('high-fives')
end

Hope that answers the question.

Best, thanks for your interest,
Seamus