You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This behavior is by design so you don't have to check for existence before each increment (which would double the network round trips). Yep, it sets the value (not key) to that string because of a marshalling incompatibility between ActiveSupport and Dalli. Just call to_i on the result or use the Dalli incr() method directly.
In issue #112 I'm providing a workaround allowing Rails.cache.increment(key, 1, :initial => nil) to return nil regardless of the underlying store.
Regarding the justification given above: the double network round trip happens only once; it's hardly a cost. And that is by design for us, because we only want to determine the initial value once as that usually is a very resource intensive operation compared to the one time extra call to memcached. For Dalli to assume the initial value is the same as the increment value is incorrect or at least arbitrary. The correct behaviour would be follow the API of the ActiveSupport::Cache store, i.e. return nil on a missing key.
Which is incompatible with MemCacheStore, which leaves the key unset and returns 0.
The text was updated successfully, but these errors were encountered: