Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incr doesn't initialize default value if ttl is expired #162

Closed
khaskelberg opened this issue Jun 28, 2022 · 1 comment
Closed

Incr doesn't initialize default value if ttl is expired #162

khaskelberg opened this issue Jun 28, 2022 · 1 comment

Comments

@khaskelberg
Copy link

Hey!

Currently when you incr on expired value it increases and returns expired value and doesn't invalidate it. I personally expected that it would increase the default value, if ttl is expired.

Here is an example test khaskelberg@49438f8

test "incr initializes default value if ttl is expired", %{cache: cache} do
  assert cache.incr(:another_counter_with_ttl, 1, ttl: 1000) == 1
  assert cache.incr(:another_counter_with_ttl) == 2

  :ok = Process.sleep(1010)
  assert cache.incr(:another_counter_with_ttl, 1, ttl: 1000) == 1
end

And here is the test ouput

  1) test entry: incr initializes default value if ttl is expired (Nebulex.Adapters.LocalEtsTest)
     test/nebulex/adapters/local_ets_test.exs:94
     Assertion with == failed
     code:  assert cache.incr(:another_counter_with_ttl, 1, ttl: 1000) == 1
     left:  3
     right: 1
     stacktrace:
       test/nebulex/adapters/local_ets_test.exs:99: (test)

.....................................................................................................................

  2) test entry: incr initializes default value if ttl is expired (Nebulex.Adapters.LocalWithShardsTest)
     test/nebulex/adapters/local_shards_test.exs:94
     Assertion with == failed
     code:  assert cache.incr(:another_counter_with_ttl, 1, ttl: 1000) == 1
     left:  3
     right: 1
     stacktrace:
       test/nebulex/adapters/local_shards_test.exs:99: (test)
@cabol
Copy link
Owner

cabol commented Jul 10, 2022

Hey! Good catch! I pushed a fix already, please try it out. I will close the issue and publish a new release but feel free to re-open it if you find an issue with the fix. Thanks!

@cabol cabol closed this as completed Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants