dalli 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

data/History.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 2.0.2
5
+ =======
6
+
7
+ - Fix all dalli\_store operations to handle nil options [#190]
8
+ - Increment and decrement with :initial => nil now return nil (lawrencepit, #112)
9
+
4
10
  2.0.1
5
11
  =======
6
12
 
@@ -25,7 +25,8 @@ module ActiveSupport
25
25
  @data = Dalli::Client.new(addresses, options)
26
26
  end
27
27
 
28
- def fetch(name, options={})
28
+ def fetch(name, options=nil)
29
+ options ||= {}
29
30
  if block_given?
30
31
  unless options[:force]
31
32
  entry = instrument(:read, name, options) do |payload|
@@ -49,7 +50,8 @@ module ActiveSupport
49
50
  end
50
51
  end
51
52
 
52
- def read(name, options={})
53
+ def read(name, options=nil)
54
+ options ||= {}
53
55
  instrument(:read, name, options) do |payload|
54
56
  entry = read_entry(name, options)
55
57
  payload[:hit] = !!entry if payload
@@ -57,17 +59,19 @@ module ActiveSupport
57
59
  end
58
60
  end
59
61
 
60
- def write(name, value, options={})
62
+ def write(name, value, options=nil)
63
+ options ||= {}
61
64
  instrument(:write, name, options) do |payload|
62
65
  write_entry(name, value, options)
63
66
  end
64
67
  end
65
68
 
66
- def exist?(name, options={})
69
+ def exist?(name, options=nil)
70
+ options ||= {}
67
71
  !!read_entry(name, options)
68
72
  end
69
73
 
70
- def delete(name, options={})
74
+ def delete(name, options=nil)
71
75
  @data.delete(name)
72
76
  end
73
77
 
@@ -94,8 +98,9 @@ module ActiveSupport
94
98
  # Calling it on a value not stored with :raw will fail.
95
99
  # :initial defaults to the amount passed in, as if the counter was initially zero.
96
100
  # memcached counters cannot hold negative values.
97
- def increment(name, amount = 1, options={}) # :nodoc:
98
- initial = options[:initial] || amount
101
+ def increment(name, amount = 1, options=nil)
102
+ options ||= {}
103
+ initial = options.has_key?(:initial) ? options[:initial] : amount
99
104
  expires_in = options[:expires_in]
100
105
  instrument(:increment, name, :amount => amount) do
101
106
  @data.incr(name, amount, expires_in, initial)
@@ -110,8 +115,9 @@ module ActiveSupport
110
115
  # Calling it on a value not stored with :raw will fail.
111
116
  # :initial defaults to zero, as if the counter was initially zero.
112
117
  # memcached counters cannot hold negative values.
113
- def decrement(name, amount = 1, options={}) # :nodoc:
114
- initial = options[:initial] || 0
118
+ def decrement(name, amount = 1, options=nil)
119
+ options ||= {}
120
+ initial = options.has_key?(:initial) ? options[:initial] : 0
115
121
  expires_in = options[:expires_in]
116
122
  instrument(:decrement, name, :amount => amount) do
117
123
  @data.decr(name, amount, expires_in, initial)
@@ -150,7 +156,6 @@ module ActiveSupport
150
156
 
151
157
  # Write an entry to the cache.
152
158
  def write_entry(key, value, options) # :nodoc:
153
- options ||= {}
154
159
  method = options[:unless_exist] ? :add : :set
155
160
  expires_in = options[:expires_in]
156
161
  @data.send(method, escape(key), value, expires_in, options)
@@ -177,7 +182,7 @@ module ActiveSupport
177
182
  key
178
183
  end
179
184
 
180
- def instrument(operation, key, options = nil)
185
+ def instrument(operation, key, options=nil)
181
186
  log(operation, key, options)
182
187
 
183
188
  if ActiveSupport::Cache::Store.instrument
@@ -189,7 +194,7 @@ module ActiveSupport
189
194
  end
190
195
  end
191
196
 
192
- def log(operation, key, options = nil)
197
+ def log(operation, key, options=nil)
193
198
  return unless logger && logger.debug?
194
199
  logger.debug("Cache #{operation}: #{key}#{options.blank? ? "" : " (#{options.inspect})"}")
195
200
  end
data/lib/dalli/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -4,9 +4,15 @@ require 'helper'
4
4
  describe 'ActiveSupport' do
5
5
  context 'active_support caching' do
6
6
 
7
- should 'write should handle nil options' do
7
+ should 'dalli_store operations should handle nil options' do
8
8
  @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122')
9
- @dalli.write('foo', 'bar', nil)
9
+ assert_equal true, @dalli.write('foo', 'bar', nil)
10
+ assert_equal 'bar', @dalli.read('foo', nil)
11
+ assert_equal 18, @dalli.fetch('lkjsadlfk', nil) { 18 }
12
+ assert_equal 18, @dalli.fetch('lkjsadlfk', nil) { 18 }
13
+ assert_equal 1, @dalli.increment('lkjsa', 1, nil)
14
+ assert_equal 2, @dalli.increment('lkjsa', 1, nil)
15
+ assert_equal 1, @dalli.decrement('lkjsa', 1, nil)
10
16
  end
11
17
 
12
18
  should 'support fetch' do
@@ -108,6 +114,20 @@ describe 'ActiveSupport' do
108
114
  assert_equal 1, @dalli.increment('counterX')
109
115
  assert_equal 2, @dalli.increment('counterX')
110
116
  assert_equal 2, @dalli.read('counterX', :raw => true).to_i
117
+
118
+ assert_equal 5, @dalli.increment('counterY1', 1, :initial => 5)
119
+ assert_equal 6, @dalli.increment('counterY1', 1, :initial => 5)
120
+ assert_equal 6, @dalli.read('counterY1', :raw => true).to_i
121
+
122
+ assert_equal nil, @dalli.increment('counterZ1', 1, :initial => nil)
123
+ assert_equal nil, @dalli.read('counterZ1')
124
+
125
+ assert_equal 5, @dalli.decrement('counterY2', 1, :initial => 5)
126
+ assert_equal 4, @dalli.decrement('counterY2', 1, :initial => 5)
127
+ assert_equal 4, @dalli.read('counterY2', :raw => true).to_i
128
+
129
+ assert_equal nil, @dalli.decrement('counterZ2', 1, :initial => nil)
130
+ assert_equal nil, @dalli.read('counterZ2')
111
131
  end
112
132
  end
113
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mini_shoulda
16
- requirement: &70253543905580 !ruby/object:Gem::Requirement
16
+ requirement: &70329087195200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70253543905580
24
+ version_requirements: *70329087195200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70253543905040 !ruby/object:Gem::Requirement
27
+ requirement: &70329087190140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70253543905040
35
+ version_requirements: *70329087190140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70253543904560 !ruby/object:Gem::Requirement
38
+ requirement: &70329087188860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70253543904560
46
+ version_requirements: *70329087188860
47
47
  description: High performance memcached client for Ruby
48
48
  email: mperham@gmail.com
49
49
  executables: []