readthis 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39c546b2720bf3e983c15c8fe9d7a60fea06cf75
4
- data.tar.gz: 0a41d522ce9f5a096bf967a344d3e71ab1c01b56
3
+ metadata.gz: f71b3b7fac83a8203aa382cb87a4684240d427df
4
+ data.tar.gz: 8e87900ed9f5fb0199d20fb674ef7b8c988886b6
5
5
  SHA512:
6
- metadata.gz: 669ad6115ac86b13bb8ff8108a839d6c9890fbf4ca456ee8bd5f06dfe53578532559a8507a9cdd8a7ed7458341def6acee7e7e051b479fef2828c3312b0f32b8
7
- data.tar.gz: 15ebfbe02678355846db403aa48b800212aeb5115c05b3b14107ba603db2e74445403ad24988b2161eaff7c5d8e0662b8c7fa1bab2a0927f290ccbf943fa5648
6
+ metadata.gz: 47a9479f67d9550b32798f8122209c569281e16d1d85402cf47af4ae7676de0fc65e6d6f5ffa87c99cc18606774f9d30a4ced4f8867ede0bdf8bb38872fbc50e
7
+ data.tar.gz: 2fe39b8a2f99bc1b4a55865cd114f49280311593ac157511874934f198f104b70ff04f3f4cdd90c1fd95794dd1b1d83965014db0afe69c60523fe7052e74549a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.5.2 2015-01-09
2
+
3
+ - Fixed: Remove the `pipeline` around `fetch_multi` writing. This will slow down
4
+ `fetch_multi` in cache miss situations for now. It prevents a difficult to
5
+ track down exception in multi-threaded situations.
6
+
1
7
  ## v0.5.1 2014-12-30
2
8
 
3
9
  - Fixed: The `clear` method now accepts an argument for compatibility with other
@@ -113,6 +113,38 @@ module Readthis
113
113
  end
114
114
  end
115
115
 
116
+ # Fetches data from the cache, using the given key. If there is data in the
117
+ # cache with the given key, then that data is returned.
118
+ #
119
+ # If there is no such data in the cache (a cache miss), then `nil` will be
120
+ # returned. However, if a block has been passed, that block will be passed
121
+ # the key and executed in the event of a cache miss. The return value of
122
+ # the block will be written to the cache under the given cache key, and
123
+ # that return value will be returned.
124
+ #
125
+ # @param [String] Key for lookup
126
+ # @param [Block] Optional block for generating the value when missing
127
+ # @param options [Hash] Optional overrides
128
+ # @option options [Boolean] :force Force a cache miss
129
+ #
130
+ # @example Typical
131
+ #
132
+ # cache.write('today', 'Monday')
133
+ # cache.fetch('today') # => "Monday"
134
+ # cache.fetch('city') # => nil
135
+ #
136
+ # @example With a block
137
+ #
138
+ # cache.fetch('city') do
139
+ # 'Duckburgh'
140
+ # end
141
+ # cache.fetch('city') # => "Duckburgh"
142
+ #
143
+ # @example Cache Miss
144
+ #
145
+ # cache.write('today', 'Monday')
146
+ # cache.fetch('today', force: true) # => nil
147
+ #
116
148
  def fetch(key, options = {})
117
149
  value = read(key, options) unless options[:force]
118
150
 
@@ -166,6 +198,20 @@ module Readthis
166
198
  end
167
199
  end
168
200
 
201
+ # Read multiple values at once from the cache. Options can be passed in the
202
+ # last argument.
203
+ #
204
+ # @overload read_multi(keys)
205
+ # Return all values for the given keys.
206
+ # @param [String] One or more keys to fetch
207
+ #
208
+ # @return [Hash] A hash mapping keys to the values found.
209
+ #
210
+ # @example
211
+ #
212
+ # cache.write('a', 1)
213
+ # cache.read_multi('a', 'b') # => { 'a' => 1, 'b' => nil }
214
+ #
169
215
  def read_multi(*keys)
170
216
  options = merged_options(extract_options!(keys))
171
217
  mapping = keys.map { |key| namespaced_key(key, options) }
@@ -182,7 +228,7 @@ module Readthis
182
228
  # executed atomically.
183
229
  #
184
230
  # @overload fetch_multi(keys)
185
- # Return all values fro the given keys, applying the block to the key
231
+ # Return all values for the given keys, applying the block to the key
186
232
  # when a value is missing.
187
233
  # @param [String] One or more keys to fetch
188
234
  #
@@ -195,18 +241,17 @@ module Readthis
195
241
  # cache.fetch_multi('a', 'b', expires_in: 60) do |key|
196
242
  # key * 2
197
243
  # end
244
+ #
198
245
  def fetch_multi(*keys)
199
246
  results = read_multi(*keys)
200
247
  options = merged_options(extract_options!(keys))
201
248
 
202
249
  invoke(:fetch_multi, keys) do |store|
203
- store.pipelined do
204
- results.each do |key, value|
205
- if value.nil?
206
- value = yield(key)
207
- write_entity(key, value, store, options)
208
- results[key] = value
209
- end
250
+ results.each do |key, value|
251
+ if value.nil?
252
+ value = yield(key)
253
+ write_entity(key, value, store, options)
254
+ results[key] = value
210
255
  end
211
256
  end
212
257
 
@@ -1,3 +1,3 @@
1
1
  module Readthis
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readthis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis