libmemcached_store 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81049d49ca34851708a4420138dcda2e5f066cc3
4
+ data.tar.gz: c2a1cab1fa37246d1c9488a826992f06d42582a6
5
+ SHA512:
6
+ metadata.gz: 0893cf06da549233d33041a00ada8de50380eb2d3bb0e95ed2534abe24c889622f9a0139272a28927edd88962000c5e6050fccb3f28f28e042043cd50ded332b
7
+ data.tar.gz: 5f935624798ce3060f7d0bcd3f0fb67f04d660c84aba61ee0451880da385cb75febc27d56895c7c5a7d2dce1077ae60605f31fcc17785fe1a9f0bc08a2f0adde
@@ -0,0 +1,105 @@
1
+ require 'active_support/cache/libmemcached_store'
2
+
3
+ # cache nils
4
+ # https://github.com/rails/rails/pull/22194
5
+ if ActiveSupport::VERSION::MAJOR < 5
6
+ ActiveSupport::Cache::Strategy::LocalCache::LocalStore.class_eval do
7
+ def fetch_entry(key, options=nil)
8
+ @data.fetch(key) { @data[key] = yield }
9
+ end
10
+ end
11
+
12
+ ActiveSupport::Cache::Strategy::LocalCache.class_eval do
13
+ def read_entry(key, options) # :nodoc:
14
+ if cache = local_cache
15
+ cache.fetch_entry(key) { super }
16
+ else
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module ActiveSupport
24
+ module Cache
25
+ class LibmemcachedLocalStore < LibmemcachedStore
26
+ include ActiveSupport::Cache::Strategy::LocalCache
27
+
28
+ # if we read from local_cache then the return value from read_entry will be an Entry,
29
+ # so convert it to it's value
30
+ def read(*args)
31
+ result = super
32
+ result = result.value if result.is_a?(ActiveSupport::Cache::Entry)
33
+ result
34
+ end
35
+
36
+ # make read multi hit local cache
37
+ def read_multi(*names)
38
+ return super unless cache = local_cache
39
+
40
+ options = names.extract_options!
41
+
42
+ missing_names = []
43
+
44
+ # We write raw values to the local cache, unlike rails MemcachedStore, so we cannot use local_cache.read_multi.
45
+ # Once read_multi_entry is available we can switch to that.
46
+ results = names.each_with_object({}) do |name, results|
47
+ value = local_cache.fetch_entry(name) do
48
+ missing_names << name
49
+ nil
50
+ end
51
+ results[name] = value unless value.nil?
52
+ end
53
+
54
+ if missing_names.any?
55
+ missing_names << options
56
+ missing = super(*missing_names)
57
+ missing.each { |k,v| cache.write_entry(k, v, nil) }
58
+ results.merge!(missing)
59
+ end
60
+
61
+ results
62
+ end
63
+
64
+ # memcached returns a fixnum on increment, but the value that is stored is raw / a string
65
+ def increment(key, amount, options={})
66
+ result = super
67
+ if result && (cache = local_cache)
68
+ cache.write(key, result.to_s)
69
+ end
70
+ result
71
+ end
72
+
73
+ # memcached returns a fixnum on decrement, but the value that is stored is raw / a string
74
+ def decrement(key, amount, options={})
75
+ result = super
76
+ if result && (cache = local_cache)
77
+ cache.write(key, result.to_s)
78
+ end
79
+ result
80
+ end
81
+
82
+ private
83
+
84
+ # when trying to do a raw read we want the marshaled value to behave the same as memcached
85
+ def read_entry(key, options)
86
+ entry = super
87
+
88
+ if options && options[:raw] && local_cache && entry && !entry.is_a?(Entry)
89
+ entry = Marshal.dump(entry)
90
+ end
91
+
92
+ entry
93
+ end
94
+
95
+ # for memcached writing raw means writing a string and not the actual value
96
+ def write_entry(key, entry, options) # :nodoc:
97
+ written = super
98
+ if options && options[:raw] && local_cache && written
99
+ local_cache.write_entry(key, Entry.new(entry.to_s), options)
100
+ end
101
+ written
102
+ end
103
+ end
104
+ end
105
+ end
@@ -119,31 +119,6 @@ module ActiveSupport
119
119
  end
120
120
  end
121
121
 
122
- def fetch_with_race_condition_ttl(key, options={}, &block)
123
- options = options.dup
124
-
125
- race_ttl = options.delete(:race_condition_ttl) || raise("Use :race_condition_ttl option or normal fetch")
126
- expires_in = options.fetch(:expires_in)
127
- options[:expires_in] = expires_in + race_ttl
128
- options[:preserve_race_condition_entry] = true
129
-
130
- value = fetch(key, options) { FetchWithRaceConditionTTLEntry.new(yield, expires_in) }
131
-
132
- return value unless value.is_a?(FetchWithRaceConditionTTLEntry)
133
-
134
- if value.expired? && !value.extended
135
- # we take care of refreshing the cache, all others should keep reading
136
- value.extended = true
137
- write(key, value, options.merge(:expires_in => value.expires_in + race_ttl))
138
-
139
- # calculate new value and store it
140
- value = FetchWithRaceConditionTTLEntry.new(yield, expires_in)
141
- write(key, value, options)
142
- end
143
-
144
- value.value
145
- end
146
-
147
122
  def read(key, options = nil)
148
123
  key = expanded_key(key)
149
124
  instrument(:read, key, options) do |payload|
@@ -281,6 +256,31 @@ module ActiveSupport
281
256
 
282
257
  private
283
258
 
259
+ def fetch_with_race_condition_ttl(key, options={}, &block)
260
+ options = options.dup
261
+
262
+ race_ttl = options.delete(:race_condition_ttl) || raise("Use :race_condition_ttl option or normal fetch")
263
+ expires_in = options.fetch(:expires_in)
264
+ options[:expires_in] = expires_in + race_ttl
265
+ options[:preserve_race_condition_entry] = true
266
+
267
+ value = fetch(key, options) { FetchWithRaceConditionTTLEntry.new(yield, expires_in) }
268
+
269
+ return value unless value.is_a?(FetchWithRaceConditionTTLEntry)
270
+
271
+ if value.expired? && !value.extended
272
+ # we take care of refreshing the cache, all others should keep reading
273
+ value.extended = true
274
+ write(key, value, options.merge(:expires_in => value.expires_in + race_ttl))
275
+
276
+ # calculate new value and store it
277
+ value = FetchWithRaceConditionTTLEntry.new(yield, expires_in)
278
+ write(key, value, options)
279
+ end
280
+
281
+ value.value
282
+ end
283
+
284
284
  def convert_race_condition_entry(value, options={})
285
285
  if !options[:preserve_race_condition_entry] && value.is_a?(FetchWithRaceConditionTTLEntry)
286
286
  value.value
@@ -1,3 +1,3 @@
1
1
  module LibmemcachedStore
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libmemcached_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Christopher Cocchi-Perrier
@@ -11,189 +10,185 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2015-06-11 00:00:00.000000000 Z
13
+ date: 2015-11-20 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: memcached
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>='
19
+ - - ">="
22
20
  - !ruby/object:Gem::Version
23
21
  version: '0'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ! '>='
26
+ - - ">="
30
27
  - !ruby/object:Gem::Version
31
28
  version: '0'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: rack
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>='
33
+ - - ">="
38
34
  - !ruby/object:Gem::Version
39
35
  version: '0'
40
36
  type: :development
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>='
40
+ - - ">="
46
41
  - !ruby/object:Gem::Version
47
42
  version: '0'
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: rake
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ! '>='
47
+ - - ">="
54
48
  - !ruby/object:Gem::Version
55
49
  version: '0'
56
50
  type: :development
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ! '>='
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: bump
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
62
69
  - !ruby/object:Gem::Version
63
70
  version: '0'
64
71
  - !ruby/object:Gem::Dependency
65
72
  name: mocha
66
73
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
74
  requirements:
69
- - - ! '>='
75
+ - - ">="
70
76
  - !ruby/object:Gem::Version
71
77
  version: '0'
72
78
  type: :development
73
79
  prerelease: false
74
80
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
81
  requirements:
77
- - - ! '>='
82
+ - - ">="
78
83
  - !ruby/object:Gem::Version
79
84
  version: '0'
80
85
  - !ruby/object:Gem::Dependency
81
86
  name: dalli
82
87
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
88
  requirements:
85
- - - ! '>='
89
+ - - ">="
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0'
88
92
  type: :development
89
93
  prerelease: false
90
94
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
95
  requirements:
93
- - - ! '>='
96
+ - - ">="
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  - !ruby/object:Gem::Dependency
97
100
  name: minitest
98
101
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
102
  requirements:
101
- - - ! '>='
103
+ - - ">="
102
104
  - !ruby/object:Gem::Version
103
105
  version: '0'
104
106
  type: :development
105
107
  prerelease: false
106
108
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
109
  requirements:
109
- - - ! '>='
110
+ - - ">="
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  - !ruby/object:Gem::Dependency
113
114
  name: minitest-rg
114
115
  requirement: !ruby/object:Gem::Requirement
115
- none: false
116
116
  requirements:
117
- - - ! '>='
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
123
  requirements:
125
- - - ! '>='
124
+ - - ">="
126
125
  - !ruby/object:Gem::Version
127
126
  version: '0'
128
127
  - !ruby/object:Gem::Dependency
129
128
  name: activesupport
130
129
  requirement: !ruby/object:Gem::Requirement
131
- none: false
132
130
  requirements:
133
- - - ! '>='
131
+ - - ">="
134
132
  - !ruby/object:Gem::Version
135
133
  version: '3'
136
134
  type: :development
137
135
  prerelease: false
138
136
  version_requirements: !ruby/object:Gem::Requirement
139
- none: false
140
137
  requirements:
141
- - - ! '>='
138
+ - - ">="
142
139
  - !ruby/object:Gem::Version
143
140
  version: '3'
144
141
  - !ruby/object:Gem::Dependency
145
142
  name: actionpack
146
143
  requirement: !ruby/object:Gem::Requirement
147
- none: false
148
144
  requirements:
149
- - - ! '>='
145
+ - - ">="
150
146
  - !ruby/object:Gem::Version
151
147
  version: '3'
152
148
  type: :development
153
149
  prerelease: false
154
150
  version_requirements: !ruby/object:Gem::Requirement
155
- none: false
156
151
  requirements:
157
- - - ! '>='
152
+ - - ">="
158
153
  - !ruby/object:Gem::Version
159
154
  version: '3'
160
- description: ! "An ActiveSupport cache store that uses the C-based libmemcached client
161
- through\n Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast,
162
- lightweight,\n and supports consistent hashing, non-blocking IO, and graceful
163
- server failover."
155
+ description: |-
156
+ An ActiveSupport cache store that uses the C-based libmemcached client through
157
+ Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
158
+ and supports consistent hashing, non-blocking IO, and graceful server failover.
164
159
  email: cocchi.c@gmail.com
165
160
  executables: []
166
161
  extensions: []
167
162
  extra_rdoc_files: []
168
163
  files:
169
164
  - lib/action_dispatch/session/libmemcached_store.rb
165
+ - lib/active_support/cache/libmemcached_local_store.rb
170
166
  - lib/active_support/cache/libmemcached_store.rb
171
167
  - lib/libmemcached_store.rb
172
168
  - lib/memcached/get_with_flags.rb
173
169
  - lib/memcached/version.rb
174
- homepage: http://github.com/ccocchi/libmemcached_store
170
+ homepage: https://github.com/ccocchi/libmemcached_store
175
171
  licenses:
176
172
  - MIT
173
+ metadata: {}
177
174
  post_install_message:
178
175
  rdoc_options: []
179
176
  require_paths:
180
177
  - lib
181
178
  required_ruby_version: !ruby/object:Gem::Requirement
182
- none: false
183
179
  requirements:
184
- - - ! '>='
180
+ - - ">="
185
181
  - !ruby/object:Gem::Version
186
182
  version: '0'
187
183
  required_rubygems_version: !ruby/object:Gem::Requirement
188
- none: false
189
184
  requirements:
190
- - - ! '>='
185
+ - - ">="
191
186
  - !ruby/object:Gem::Version
192
187
  version: '0'
193
188
  requirements: []
194
189
  rubyforge_project:
195
- rubygems_version: 1.8.23
190
+ rubygems_version: 2.4.5.1
196
191
  signing_key:
197
- specification_version: 3
192
+ specification_version: 4
198
193
  summary: ActiveSupport 3+ cache store for the C-based libmemcached client
199
194
  test_files: []