moneta 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +176 -0
- data/.travis.yml +57 -23
- data/CHANGES +12 -0
- data/Gemfile +89 -64
- data/README.md +40 -14
- data/feature_matrix.yaml +1 -0
- data/lib/action_dispatch/middleware/session/moneta_store.rb +1 -0
- data/lib/active_support/cache/moneta_store.rb +5 -5
- data/lib/moneta.rb +9 -1
- data/lib/moneta/adapters/activerecord.rb +35 -19
- data/lib/moneta/adapters/activesupportcache.rb +3 -7
- data/lib/moneta/adapters/cassandra.rb +24 -16
- data/lib/moneta/adapters/client.rb +13 -9
- data/lib/moneta/adapters/couch.rb +220 -80
- data/lib/moneta/adapters/datamapper.rb +1 -0
- data/lib/moneta/adapters/file.rb +9 -6
- data/lib/moneta/adapters/hbase.rb +1 -1
- data/lib/moneta/adapters/kyotocabinet.rb +8 -7
- data/lib/moneta/adapters/leveldb.rb +1 -1
- data/lib/moneta/adapters/lmdb.rb +3 -4
- data/lib/moneta/adapters/lruhash.rb +29 -62
- data/lib/moneta/adapters/memcached.rb +1 -0
- data/lib/moneta/adapters/memcached/dalli.rb +1 -1
- data/lib/moneta/adapters/memcached/native.rb +10 -8
- data/lib/moneta/adapters/mongo.rb +1 -0
- data/lib/moneta/adapters/mongo/base.rb +3 -3
- data/lib/moneta/adapters/mongo/moped.rb +12 -13
- data/lib/moneta/adapters/mongo/official.rb +7 -8
- data/lib/moneta/adapters/null.rb +1 -2
- data/lib/moneta/adapters/pstore.rb +3 -2
- data/lib/moneta/adapters/redis.rb +3 -3
- data/lib/moneta/adapters/restclient.rb +12 -3
- data/lib/moneta/adapters/riak.rb +2 -2
- data/lib/moneta/adapters/sequel.rb +112 -119
- data/lib/moneta/adapters/sqlite.rb +3 -3
- data/lib/moneta/adapters/tokyotyrant.rb +1 -1
- data/lib/moneta/builder.rb +0 -1
- data/lib/moneta/enumerable.rb +38 -0
- data/lib/moneta/expires.rb +12 -12
- data/lib/moneta/fallback.rb +84 -0
- data/lib/moneta/lock.rb +1 -1
- data/lib/moneta/logger.rb +2 -2
- data/lib/moneta/mixins.rb +12 -10
- data/lib/moneta/optionmerger.rb +0 -1
- data/lib/moneta/pool.rb +301 -31
- data/lib/moneta/proxy.rb +2 -2
- data/lib/moneta/server.rb +9 -12
- data/lib/moneta/shared.rb +1 -1
- data/lib/moneta/stack.rb +6 -6
- data/lib/moneta/synchronize.rb +3 -3
- data/lib/moneta/transformer.rb +19 -17
- data/lib/moneta/transformer/config.rb +6 -5
- data/lib/moneta/transformer/helper.rb +3 -3
- data/lib/moneta/transformer/helper/bson.rb +18 -15
- data/lib/moneta/utils.rb +3 -9
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/weak_each_key.rb +2 -4
- data/lib/rack/cache/moneta.rb +16 -13
- data/lib/rack/moneta_rest.rb +2 -2
- data/lib/rack/session/moneta.rb +3 -4
- data/moneta.gemspec +8 -0
- data/script/benchmarks +55 -32
- data/script/reconfigure-couchdb +13 -0
- data/script/start-hbase +1 -0
- data/script/start-services +2 -10
- data/spec/active_support/cache_moneta_store_spec.rb +3 -1
- data/spec/features/concurrent_create.rb +31 -10
- data/spec/features/concurrent_increment.rb +27 -19
- data/spec/features/increment.rb +41 -41
- data/spec/helper.rb +2 -42
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +4 -1
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +4 -1
- data/spec/moneta/adapters/activesupportcache/standard_activesupportcache_spec.rb +14 -0
- data/spec/moneta/adapters/couch/adapter_couch_spec.rb +199 -2
- data/spec/moneta/adapters/couch/standard_couch_spec.rb +8 -2
- data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +7 -1
- data/spec/moneta/adapters/faraday_helper.rb +9 -0
- data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +2 -2
- data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +1 -1
- data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +1 -1
- data/spec/moneta/adapters/{memcached/helper.rb → memcached_helper.rb} +0 -0
- data/spec/moneta/adapters/null/null_adapter_spec.rb +1 -1
- data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +7 -5
- data/spec/moneta/adapters/restclient/helper.rb +12 -0
- data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +9 -6
- data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +4 -0
- data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +6 -2
- data/spec/moneta/adapters/tokyotyrant/helper.rb +12 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +5 -2
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +5 -1
- data/spec/moneta/proxies/enumerable/enumerable_spec.rb +26 -0
- data/spec/moneta/proxies/fallback/fallback_spec.rb +42 -0
- data/spec/moneta/proxies/pool/pool_spec.rb +319 -6
- data/spec/restserver.rb +40 -0
- metadata +122 -7
- data/script/install-kyotocabinet +0 -17
data/lib/moneta/proxy.rb
CHANGED
@@ -128,8 +128,8 @@ module Moneta
|
|
128
128
|
end
|
129
129
|
|
130
130
|
# (see Defaults::ClassMethods#not_supports)
|
131
|
-
def not_supports
|
132
|
-
@features_mask = (
|
131
|
+
def not_supports(*features)
|
132
|
+
@features_mask = (features_mask | features).freeze
|
133
133
|
super
|
134
134
|
end
|
135
135
|
end
|
data/lib/moneta/server.rb
CHANGED
@@ -30,12 +30,10 @@ module Moneta
|
|
30
30
|
@stop = false
|
31
31
|
@running = true
|
32
32
|
begin
|
33
|
-
until @stop
|
34
|
-
mainloop
|
35
|
-
end
|
33
|
+
mainloop until @stop
|
36
34
|
ensure
|
37
35
|
File.unlink(@socket) if @socket
|
38
|
-
@ios.each{ |io| io.close rescue nil }
|
36
|
+
@ios.each { |io| io.close rescue nil }
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
@@ -74,7 +72,7 @@ module Moneta
|
|
74
72
|
rescue SignalException => ex
|
75
73
|
warn "Moneta::Server - #{ex.message}"
|
76
74
|
raise if ex.signo == 15 || ex.signo == 2 # SIGTERM or SIGINT
|
77
|
-
rescue
|
75
|
+
rescue => ex
|
78
76
|
warn "Moneta::Server - #{ex.message}"
|
79
77
|
end
|
80
78
|
|
@@ -83,15 +81,14 @@ module Moneta
|
|
83
81
|
@clients.delete(io)
|
84
82
|
end
|
85
83
|
|
86
|
-
def pack(
|
87
|
-
s = Marshal.dump(
|
84
|
+
def pack(obj)
|
85
|
+
s = Marshal.dump(obj)
|
88
86
|
[s.bytesize].pack('N') << s
|
89
87
|
end
|
90
88
|
|
91
89
|
def handle(io, buffer)
|
92
|
-
buffer = @clients[io]
|
93
90
|
return if buffer.bytesize < 8 # At least 4 bytes for the marshalled array
|
94
|
-
size = buffer[0,4].unpack('N').first
|
91
|
+
size = buffer[0, 4].unpack('N').first
|
95
92
|
if size > MAXSIZE
|
96
93
|
delete_client(io)
|
97
94
|
return
|
@@ -101,7 +98,7 @@ module Moneta
|
|
101
98
|
method, *args = Marshal.load(buffer.slice!(0, size))
|
102
99
|
case method
|
103
100
|
when :key?, :load, :delete, :increment, :create
|
104
|
-
io.write(pack
|
101
|
+
io.write(pack(@store.send(method, *args)))
|
105
102
|
when :features
|
106
103
|
# all features except each_key are supported
|
107
104
|
io.write(pack(@store.features - [:each_key]))
|
@@ -114,9 +111,9 @@ module Moneta
|
|
114
111
|
rescue IOError => ex
|
115
112
|
warn "Moneta::Server - #{ex.message}" unless ex.message =~ /closed/
|
116
113
|
delete_client(io)
|
117
|
-
rescue
|
114
|
+
rescue => ex
|
118
115
|
warn "Moneta::Server - #{ex.message}"
|
119
|
-
io.write(pack
|
116
|
+
io.write(pack(Exception.new(ex.message)))
|
120
117
|
end
|
121
118
|
|
122
119
|
def start(options)
|
data/lib/moneta/shared.rb
CHANGED
@@ -42,7 +42,7 @@ module Moneta
|
|
42
42
|
connect
|
43
43
|
yield
|
44
44
|
rescue Errno::ECONNRESET, Errno::EPIPE, IOError, SystemCallError
|
45
|
-
@connect_lock.synchronize{ close unless @server }
|
45
|
+
@connect_lock.synchronize { close unless @server }
|
46
46
|
tries ||= 0
|
47
47
|
(tries += 1) < 3 ? retry : raise
|
48
48
|
end
|
data/lib/moneta/stack.rb
CHANGED
@@ -42,7 +42,7 @@ module Moneta
|
|
42
42
|
|
43
43
|
# (see Proxy#key?)
|
44
44
|
def key?(key, options = {})
|
45
|
-
@stack.any? {|s| s.key?(key, options) }
|
45
|
+
@stack.any? { |s| s.key?(key, options) }
|
46
46
|
end
|
47
47
|
|
48
48
|
# (see Proxy#load)
|
@@ -56,21 +56,21 @@ module Moneta
|
|
56
56
|
|
57
57
|
# (see Proxy#store)
|
58
58
|
def store(key, value, options = {})
|
59
|
-
@stack.each {|s| s.store(key, value, options) }
|
59
|
+
@stack.each { |s| s.store(key, value, options) }
|
60
60
|
value
|
61
61
|
end
|
62
62
|
|
63
63
|
# (see Proxy#increment)
|
64
64
|
def increment(key, amount = 1, options = {})
|
65
65
|
last = nil
|
66
|
-
@stack.each {|s| last = s.increment(key, amount, options) }
|
66
|
+
@stack.each { |s| last = s.increment(key, amount, options) }
|
67
67
|
last
|
68
68
|
end
|
69
69
|
|
70
70
|
# (see Proxy#create)
|
71
71
|
def create(key, value, options = {})
|
72
72
|
last = false
|
73
|
-
@stack.each {|s| last = s.create(key, value, options) }
|
73
|
+
@stack.each { |s| last = s.create(key, value, options) }
|
74
74
|
last
|
75
75
|
end
|
76
76
|
|
@@ -84,13 +84,13 @@ module Moneta
|
|
84
84
|
|
85
85
|
# (see Proxy#clear)
|
86
86
|
def clear(options = {})
|
87
|
-
@stack.each {|s| s.clear(options) }
|
87
|
+
@stack.each { |s| s.clear(options) }
|
88
88
|
self
|
89
89
|
end
|
90
90
|
|
91
91
|
# (see Proxy#close)
|
92
92
|
def close
|
93
|
-
@stack.each {|s| s.close }
|
93
|
+
@stack.each { |s| s.close }
|
94
94
|
nil
|
95
95
|
end
|
96
96
|
|
data/lib/moneta/synchronize.rb
CHANGED
@@ -21,7 +21,7 @@ module Moneta
|
|
21
21
|
raise 'Already locked' if @locked
|
22
22
|
enter_primitive ? @locked = true : false
|
23
23
|
end
|
24
|
-
|
24
|
+
alias try_lock try_enter
|
25
25
|
|
26
26
|
# Enter critical section (blocking)
|
27
27
|
#
|
@@ -36,7 +36,7 @@ module Moneta
|
|
36
36
|
end
|
37
37
|
false
|
38
38
|
end
|
39
|
-
|
39
|
+
alias lock enter
|
40
40
|
|
41
41
|
# Leave critical section
|
42
42
|
def leave
|
@@ -45,7 +45,7 @@ module Moneta
|
|
45
45
|
@locked = false
|
46
46
|
nil
|
47
47
|
end
|
48
|
-
|
48
|
+
alias unlock leave
|
49
49
|
|
50
50
|
# Is the lock acquired?
|
51
51
|
def locked?
|
data/lib/moneta/transformer.rb
CHANGED
@@ -19,7 +19,7 @@ module Moneta
|
|
19
19
|
# @api public
|
20
20
|
class Transformer < Proxy
|
21
21
|
class << self
|
22
|
-
|
22
|
+
alias original_new new
|
23
23
|
|
24
24
|
# @param [Moneta store] adapter The underlying store
|
25
25
|
# @param [Hash] options
|
@@ -49,13 +49,13 @@ module Moneta
|
|
49
49
|
raise ArgumentError, 'Invalid value transformer chain' if @value_validator !~ values.map(&:inspect).join
|
50
50
|
|
51
51
|
klass = Class.new(self)
|
52
|
-
klass.class_eval <<-
|
52
|
+
klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
53
53
|
def initialize(adapter, options = {})
|
54
54
|
super
|
55
55
|
#{compile_initializer('key', keys)}
|
56
56
|
#{compile_initializer('value', values)}
|
57
57
|
end
|
58
|
-
|
58
|
+
END_EVAL
|
59
59
|
|
60
60
|
key, key_opts = compile_transformer(keys, 'key')
|
61
61
|
dump, dump_opts = compile_transformer(values, 'value')
|
@@ -78,7 +78,7 @@ module Moneta
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def compile_key_transformer(klass, key, key_opts)
|
81
|
-
klass.class_eval <<-
|
81
|
+
klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
82
82
|
not_supports :each_key
|
83
83
|
|
84
84
|
def key?(key, options = {})
|
@@ -129,11 +129,11 @@ module Moneta
|
|
129
129
|
@adapter.merge!(t_keys.zip(values), #{without :raw, key_opts}, &block)
|
130
130
|
self
|
131
131
|
end
|
132
|
-
|
132
|
+
END_EVAL
|
133
133
|
end
|
134
134
|
|
135
135
|
def compile_value_transformer(klass, load, load_opts, dump, dump_opts)
|
136
|
-
klass.class_eval <<-
|
136
|
+
klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
137
137
|
def load(key, options = {})
|
138
138
|
value = @adapter.load(key, #{without :raw, load_opts})
|
139
139
|
value && !options[:raw] ? #{load} : value
|
@@ -197,11 +197,11 @@ module Moneta
|
|
197
197
|
@adapter.merge!(t_pairs, #{without :raw, dump_opts}, &block)
|
198
198
|
self
|
199
199
|
end
|
200
|
-
|
200
|
+
END_EVAL
|
201
201
|
end
|
202
202
|
|
203
203
|
def compile_key_value_transformer(klass, key, key_opts, load, load_opts, dump, dump_opts)
|
204
|
-
klass.class_eval <<-
|
204
|
+
klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
205
205
|
not_supports :each_key
|
206
206
|
|
207
207
|
def key?(key, options = {})
|
@@ -292,7 +292,7 @@ module Moneta
|
|
292
292
|
@adapter.merge!(t_pairs, #{without :raw, key_opts, dump_opts}, &block)
|
293
293
|
self
|
294
294
|
end
|
295
|
-
|
295
|
+
END_EVAL
|
296
296
|
end
|
297
297
|
|
298
298
|
# Compile option initializer
|
@@ -305,19 +305,21 @@ module Moneta
|
|
305
305
|
end.join("\n")
|
306
306
|
end
|
307
307
|
|
308
|
-
def compile_validator(
|
309
|
-
Regexp.new('\A' +
|
310
|
-
|
311
|
-
|
308
|
+
def compile_validator(str)
|
309
|
+
Regexp.new('\A' +
|
310
|
+
str.gsub(/\w+/) do
|
311
|
+
'(' + TRANSFORMER.select { |_, v| v.first.to_s == $& }.map { |v| ":#{v.first}" }.join('|') + ')'
|
312
|
+
end.gsub(/\s+/, '') +
|
313
|
+
'\Z')
|
312
314
|
end
|
313
315
|
|
314
316
|
# Returned compiled transformer code string
|
315
|
-
def compile_transformer(transformer, var,
|
317
|
+
def compile_transformer(transformer, var, idx = 2)
|
316
318
|
value, options = var, []
|
317
319
|
transformer.each do |name|
|
318
320
|
raise ArgumentError, "Unknown transformer #{name}" unless t = TRANSFORMER[name]
|
319
321
|
require t[3] if t[3]
|
320
|
-
code = t[
|
322
|
+
code = t[idx]
|
321
323
|
options += code.scan(/options\[:(\w+)\]/).flatten
|
322
324
|
value =
|
323
325
|
if t[0] == :serialize && var == 'key'
|
@@ -326,11 +328,11 @@ module Moneta
|
|
326
328
|
code % value
|
327
329
|
end
|
328
330
|
end
|
329
|
-
|
331
|
+
[value, options]
|
330
332
|
end
|
331
333
|
|
332
334
|
def class_name(keys, values)
|
333
|
-
camel_case = lambda{ |sym| sym.to_s.split('_').map(&:capitalize).join }
|
335
|
+
camel_case = lambda { |sym| sym.to_s.split('_').map(&:capitalize).join }
|
334
336
|
(keys.empty? ? '' : keys.map(&camel_case).join + 'Key') +
|
335
337
|
(values.empty? ? '' : values.map(&camel_case).join + 'Value')
|
336
338
|
end
|
@@ -22,7 +22,8 @@ module Moneta
|
|
22
22
|
zlib: [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
|
23
23
|
base64: [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ],
|
24
24
|
urlsafe_base64: [
|
25
|
-
|
25
|
+
:encode, 'Base64.urlsafe_decode64(%s)', 'Base64.urlsafe_encode64(%s)', 'base64'
|
26
|
+
],
|
26
27
|
escape: [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
|
27
28
|
hex: [ :encode, "[%s].pack('H*')", "%s.unpack('H*').first" ],
|
28
29
|
qp: [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
|
@@ -42,13 +43,13 @@ module Moneta
|
|
42
43
|
prefix: [ :prefix, nil, '(options[:prefix] || @prefix)+%s' ],
|
43
44
|
spread: [ :spread, nil, 'Helper.spread(%s)' ],
|
44
45
|
to_s: [ :string, nil, '%s.to_s' ],
|
45
|
-
inspect: [ :string, nil, '%s.inspect' ]
|
46
|
-
}
|
46
|
+
inspect: [ :string, nil, '%s.inspect' ]
|
47
|
+
}.freeze
|
47
48
|
|
48
49
|
# Allowed value transformers (Read it like a regular expression!)
|
49
|
-
VALUE_TRANSFORMER = 'serialize? compress? hmac? encode?'
|
50
|
+
VALUE_TRANSFORMER = 'serialize? compress? hmac? encode?'.freeze
|
50
51
|
|
51
52
|
# Allowed key transformers (Read it like a regular expression!)
|
52
|
-
KEY_TRANSFORMER = '(serialize | string)? prefix? ((encode? truncate?) | (digest spread?))?'
|
53
|
+
KEY_TRANSFORMER = '(serialize | string)? prefix? ((encode? truncate?) | (digest spread?))?'.freeze
|
53
54
|
end
|
54
55
|
end
|
@@ -5,11 +5,11 @@ module Moneta
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
def escape(value)
|
8
|
-
value.gsub(/[^a-zA-Z0-9_-]+/){ '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase }
|
8
|
+
value.gsub(/[^a-zA-Z0-9_-]+/) { '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase }
|
9
9
|
end
|
10
10
|
|
11
11
|
def unescape(value)
|
12
|
-
value.gsub(/((?:%[0-9a-fA-F]{2})+)/){ [
|
12
|
+
value.gsub(/((?:%[0-9a-fA-F]{2})+)/) { |matches| [matches[1].delete('%')].pack('H*') }
|
13
13
|
end
|
14
14
|
|
15
15
|
def hmacverify(value, secret)
|
@@ -24,7 +24,7 @@ module Moneta
|
|
24
24
|
def truncate(value, maxlen)
|
25
25
|
if value.size >= maxlen
|
26
26
|
digest = Digest::MD5.hexdigest(value)
|
27
|
-
value = value[0, maxlen-digest.size] << digest
|
27
|
+
value = value[0, maxlen - digest.size] << digest
|
28
28
|
end
|
29
29
|
value
|
30
30
|
end
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module Moneta
|
2
2
|
class Transformer
|
3
|
-
module Helper
|
4
|
-
|
3
|
+
module Helper
|
4
|
+
# @api private
|
5
|
+
module BSON
|
6
|
+
extend self
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
if ::BSON::VERSION >= '4.0.0'
|
9
|
+
def load(value)
|
10
|
+
::BSON::Document.from_bson(::BSON::ByteBuffer.new(value))['v']
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def dump(value)
|
14
|
+
::BSON::Document['v' => value].to_bson.to_s
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def load(value)
|
18
|
+
::BSON::Document.from_bson(::StringIO.new(value))['v']
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
def dump(value)
|
22
|
+
::BSON::Document['v' => value].to_bson
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
data/lib/moneta/utils.rb
CHANGED
@@ -5,9 +5,9 @@ module Moneta
|
|
5
5
|
|
6
6
|
def without(hash, *keys)
|
7
7
|
return hash if hash.empty?
|
8
|
-
if keys.any? {|k| hash.include?(k) }
|
8
|
+
if keys.any? { |k| hash.include?(k) }
|
9
9
|
hash = hash.dup
|
10
|
-
keys.each {|k| hash.delete(k) }
|
10
|
+
keys.each { |k| hash.delete(k) }
|
11
11
|
end
|
12
12
|
hash
|
13
13
|
end
|
@@ -15,14 +15,8 @@ module Moneta
|
|
15
15
|
def only(hash, *keys)
|
16
16
|
return hash if hash.empty?
|
17
17
|
ret = {}
|
18
|
-
keys.each {|k| ret[k] = hash[k] }
|
18
|
+
keys.each { |k| ret[k] = hash[k] }
|
19
19
|
ret
|
20
20
|
end
|
21
|
-
|
22
|
-
def to_int(value)
|
23
|
-
intvalue = value.to_i
|
24
|
-
raise "#{value.inspect} is not an integer value" unless value == nil || intvalue.to_s == value.to_s
|
25
|
-
intvalue
|
26
|
-
end
|
27
21
|
end
|
28
22
|
end
|
data/lib/moneta/version.rb
CHANGED
data/lib/moneta/weak_each_key.rb
CHANGED
@@ -31,6 +31,8 @@ module Moneta
|
|
31
31
|
|
32
32
|
protected
|
33
33
|
|
34
|
+
attr_reader :all_keys
|
35
|
+
|
34
36
|
def wrap(name, *args)
|
35
37
|
case name
|
36
38
|
when :create, :store, :increment, :create
|
@@ -63,10 +65,6 @@ module Moneta
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
def all_keys
|
67
|
-
@all_keys
|
68
|
-
end
|
69
|
-
|
70
68
|
def each_key_save(key)
|
71
69
|
@all_keys = Set.new(@all_keys).add(key)
|
72
70
|
end
|
data/lib/rack/cache/moneta.rb
CHANGED
@@ -14,18 +14,21 @@ module Rack
|
|
14
14
|
|
15
15
|
def resolve(uri)
|
16
16
|
cache = Rack::Cache::Moneta[uri.to_s.sub(%r{^moneta://}, '')] ||=
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
begin
|
18
|
+
options = parse_query(uri.query)
|
19
|
+
options.keys.each do |key|
|
20
|
+
options[key.to_sym] =
|
21
|
+
case value = options.delete(key)
|
22
|
+
when 'true'
|
23
|
+
true
|
24
|
+
when 'false'
|
25
|
+
false
|
26
|
+
else
|
27
|
+
value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
::Moneta.new(uri.host.to_sym, options)
|
31
|
+
end
|
29
32
|
new(cache)
|
30
33
|
end
|
31
34
|
end
|
@@ -82,7 +85,7 @@ module Rack
|
|
82
85
|
def write(body, ttl = 0)
|
83
86
|
buf = StringIO.new
|
84
87
|
key, size = slurp(body) { |part| buf.write(part) }
|
85
|
-
@cache.store(key, buf.string, ttl == 0 ? {} : {expires: ttl})
|
88
|
+
@cache.store(key, buf.string, ttl == 0 ? {} : { expires: ttl })
|
86
89
|
[key, size]
|
87
90
|
end
|
88
91
|
|