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

Increment and Decrement with :initial => nil doesn't return nil on missing key. #112

Closed
lawrencepit opened this issue Aug 11, 2011 · 4 comments

Comments

@lawrencepit
Copy link
Contributor

This is somewhat related to issue #68.

When calling increment or decrement with the option :initial => nil, then on a missing key it will not return nil, but the increment amount.

@mperham
Copy link
Collaborator

mperham commented Mar 29, 2012

Sorry, I guess I never saw this issue. What's the use case for this functionality? Why would you want to create a nil counter?

@lawrencepit
Copy link
Contributor Author

  1. I think it should be consistent with the Rails.cache API (to aid with tests as well) :

#68 (comment)

  1. The use case: we want to prevent doing this:
Rails.cache.increment(cache_key, 1, :initial => very_resource_intensive_and_dynamic_operation)

instead we want to do:

next = Rails.cache.increment(cache_key, 1, :initial => nil)
unless next
  initial = very_resource_intensive_and_dynamic_operation
  next = Rails.cache.increment(cache_key, 1, :initial => initial)
end

so the resource intensive operation is performed only once during the lifetime of the service.

@mperham
Copy link
Collaborator

mperham commented Mar 29, 2012

Fair enough. Can you send a pull request please and be sure to update History.md with a line to give yourself credit.

lawrencepit added a commit to lawrencepit/dalli that referenced this issue Mar 30, 2012
@lawrencepit
Copy link
Contributor Author

See #189

mperham added a commit that referenced this issue Mar 30, 2012
Issue #112 Increment and Decrement with :initial => nil should return nil
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