h2ocube_rails_cache 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2cfe66da39df5c16bf3aef04e9e33b11ad5e1518588916515965f67973ccd4f
4
- data.tar.gz: 24d05e2c7afcbc6ca316bbb51028b172f9874de56c1cdccf068c3adce310e489
3
+ metadata.gz: aeb85c3d49fde5bb5ed13dea42a264e1c6aac05cffa0e42bf8738f22731792f5
4
+ data.tar.gz: 8b04a9d15740a8b617468019278d96734fd43c87276e92d98fb33e3d8a4d1fca
5
5
  SHA512:
6
- metadata.gz: 462463ed9d937cffa39fb84b04de25c7674ae5d3b7acab81bb7fc7c8f5e0471f3b652d51b24bbfd3c927628a6af4d4346651fe389bdc5e0e10ae975e45a5896a
7
- data.tar.gz: aaf774d66b1203f2db36422c56b626b14c9f770645f0171f31cbf10d36fe8e77205dfd2d41b8a5bdc7d6043997cac5e7019c8dcfc733030fb80b3a112610d902
6
+ metadata.gz: 2c2bc8655b53395613b183019858d6dc61b8776cc0328cd0bd250c0a5cf75c322f0d33fdc6e671cf8118c85634ab2f3a0a02044b409dd9933f34200a972b414d
7
+ data.tar.gz: 8e9511aba23192c112cdc955eb1ade7ad30de44a40729011905f3ef551075a6c3f42b7f045ba333e472185540bde71ba8e2c28adda00b922bd582dcbe3b6546a
data/README.md CHANGED
@@ -21,6 +21,7 @@ And then execute:
21
21
  * `read key, options = {}`
22
22
  * `read_multi *keys`
23
23
  * `write key, entry, options = {}`
24
+ * `write_multi hash`
24
25
  * `fetch key, options = {}, &block`
25
26
  * `delete key, options = {}`
26
27
  * `exist? key, options = {}`
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'h2ocube_rails_cache'
7
- gem.version = '0.3.0'
7
+ gem.version = '0.3.1'
8
8
  gem.authors = ['Ben']
9
9
  gem.email = ['ben@h2ocube.com']
10
10
  gem.description = 'Just an redis cache.'
@@ -53,7 +53,7 @@ module ActiveSupport
53
53
  key = normalize_key key
54
54
  return nil if key.start_with?('http')
55
55
  instrument :read, key, options do
56
- exist?(key) ? load_entry(@data.get(key)) : nil
56
+ load_entry @data.get(key)
57
57
  end
58
58
  end
59
59
 
@@ -64,15 +64,15 @@ module ActiveSupport
64
64
  end
65
65
 
66
66
  def read_multi(*names)
67
- results = {}
67
+ keys = names.map { |name| normalize_key(name) }
68
+ values = @data.mget(*keys)
68
69
 
69
- names.each do |name|
70
- entry = read(name)
71
-
72
- results[name] = entry unless entry.nil?
70
+ names.zip(values).each_with_object({}) do |(name, value), results|
71
+ if value
72
+ entry = load_entry(value)
73
+ results[name] = entry.value unless entry.nil?
74
+ end
73
75
  end
74
-
75
- results
76
76
  end
77
77
 
78
78
  def write(key, entry, opts = {})
@@ -99,6 +99,16 @@ module ActiveSupport
99
99
  end
100
100
  end
101
101
 
102
+ def write_multi(hash)
103
+ instrument :write_multi, hash do
104
+ entries = hash.each_with_object({}) do |(name, value), memo|
105
+ memo[normalize_key(name)] = dump_entry value
106
+ end
107
+
108
+ @data.mapped_mset entries
109
+ end
110
+ end
111
+
102
112
  def delete(key, options = {})
103
113
  options.reverse_merge! config
104
114
  key = normalize_key key
@@ -202,6 +212,8 @@ module ActiveSupport
202
212
  end
203
213
 
204
214
  def load_entry(entry)
215
+ return nil if entry.nil?
216
+
205
217
  begin
206
218
  Marshal.load(entry)
207
219
  rescue
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: h2ocube_rails_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis