any_cache 0.3.1 → 0.4.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 +1 -1
- data/.travis.yml +24 -24
- data/CHANGELOG.md +8 -0
- data/README.md +66 -16
- data/any_cache.gemspec +3 -3
- data/bin/rspec +1 -1
- data/lib/any_cache.rb +2 -0
- data/lib/any_cache/adapters/active_support_dalli_store.rb +17 -13
- data/lib/any_cache/adapters/active_support_mem_cache_store.rb +25 -12
- data/lib/any_cache/adapters/active_support_naive_store.rb +9 -0
- data/lib/any_cache/adapters/active_support_redis_cache_store.rb +29 -15
- data/lib/any_cache/adapters/basic.rb +11 -0
- data/lib/any_cache/adapters/dalli.rb +35 -10
- data/lib/any_cache/adapters/delegator.rb +6 -4
- data/lib/any_cache/adapters/redis.rb +28 -7
- data/lib/any_cache/adapters/redis_store.rb +12 -6
- data/lib/any_cache/delegation.rb +1 -1
- data/lib/any_cache/dumper.rb +55 -0
- data/lib/any_cache/dumper/interface_access_mixin.rb +41 -0
- data/lib/any_cache/patches/dalli_store.rb +0 -1
- data/lib/any_cache/version.rb +1 -1
- metadata +9 -7
@@ -16,6 +16,7 @@ module AnyCache::Adapters
|
|
16
16
|
driver.respond_to?(:read_multi) &&
|
17
17
|
driver.respond_to?(:write) &&
|
18
18
|
driver.respond_to?(:write_multi) &&
|
19
|
+
driver.respond_to?(:fetch) &&
|
19
20
|
driver.respond_to?(:fetch_multi) &&
|
20
21
|
driver.respond_to?(:delete) &&
|
21
22
|
driver.respond_to?(:delete_matched) &&
|
@@ -24,8 +25,8 @@ module AnyCache::Adapters
|
|
24
25
|
driver.respond_to?(:expire) &&
|
25
26
|
driver.respond_to?(:persist) &&
|
26
27
|
driver.respond_to?(:clear) &&
|
27
|
-
driver.respond_to?(:
|
28
|
-
driver.respond_to?(:
|
28
|
+
driver.respond_to?(:cleanup) &&
|
29
|
+
driver.respond_to?(:exist?)
|
29
30
|
end
|
30
31
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
31
32
|
end
|
@@ -36,6 +37,7 @@ module AnyCache::Adapters
|
|
36
37
|
:read_multi,
|
37
38
|
:write,
|
38
39
|
:write_multi,
|
40
|
+
:fetch,
|
39
41
|
:fetch_multi,
|
40
42
|
:delete,
|
41
43
|
:delete_matched,
|
@@ -44,7 +46,7 @@ module AnyCache::Adapters
|
|
44
46
|
:expire,
|
45
47
|
:persist,
|
46
48
|
:clear,
|
47
|
-
:
|
48
|
-
:
|
49
|
+
:cleanup,
|
50
|
+
:exist?
|
49
51
|
end
|
50
52
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module AnyCache::Adapters
|
4
4
|
# @api private
|
5
5
|
# @since 0.1.0
|
6
|
-
class Redis < Basic
|
6
|
+
class Redis < Basic # rubocop:disable Metrics/ClassLength
|
7
7
|
class << self
|
8
8
|
# @param driver [Object]
|
9
9
|
# @return [Boolean]
|
@@ -61,45 +61,57 @@ module AnyCache::Adapters
|
|
61
61
|
:scan
|
62
62
|
|
63
63
|
# @param key [String]
|
64
|
-
# @
|
64
|
+
# @option raw [Boolean]
|
65
65
|
# @return [Object]
|
66
66
|
#
|
67
67
|
# @api private
|
68
68
|
# @since 0.1.0
|
69
69
|
def read(key, **options)
|
70
|
-
get(key)
|
70
|
+
value = get(key)
|
71
|
+
raw = options.fetch(:raw, false)
|
72
|
+
|
73
|
+
raw ? value : detransform_value(value)
|
71
74
|
end
|
72
75
|
|
73
76
|
# @param keys [Array<String>]
|
74
|
-
# @
|
77
|
+
# @option raw [Boolean]
|
75
78
|
# @return [Hash]
|
76
79
|
#
|
77
80
|
# @api private
|
78
81
|
# @since 0.3.0
|
79
82
|
def read_multi(*keys, **options)
|
80
|
-
|
83
|
+
raw = options.fetch(:raw, false)
|
84
|
+
entries = mapped_mget(*keys)
|
85
|
+
|
86
|
+
raw ? entries : detransform_pairset(entries)
|
81
87
|
end
|
82
88
|
|
83
89
|
# @param key [String]
|
84
90
|
# @param value [Object]
|
91
|
+
# @option raw [Boolean]
|
85
92
|
# @option expires_in [NilClass, Integer] Time in seconds
|
86
93
|
# @return [void]
|
87
94
|
#
|
88
95
|
# @api private
|
89
96
|
# @since 0.1.0
|
90
97
|
def write(key, value, **options)
|
98
|
+
raw = options.fetch(:raw, false)
|
91
99
|
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
|
100
|
+
value = transform_value(value) unless raw
|
92
101
|
|
93
102
|
expires_in ? setex(key, expires_in, value) : set(key, value)
|
94
103
|
end
|
95
104
|
|
96
105
|
# @param entries [Hash]
|
97
|
-
# @
|
106
|
+
# @option raw [Boolean]
|
98
107
|
# @return [void]
|
99
108
|
#
|
100
109
|
# @api private
|
101
110
|
# @since 0.3.0
|
102
111
|
def write_multi(entries, **options)
|
112
|
+
raw = options.fetch(:raw, false)
|
113
|
+
entries = transform_pairset(entries) unless raw
|
114
|
+
|
103
115
|
mapped_mset(entries)
|
104
116
|
end
|
105
117
|
|
@@ -115,7 +127,7 @@ module AnyCache::Adapters
|
|
115
127
|
force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call)
|
116
128
|
|
117
129
|
# NOTE: think about #pipelined
|
118
|
-
read(key).tap { |value| return value if value } unless force_rewrite
|
130
|
+
read(key, **options).tap { |value| return value if value } unless force_rewrite
|
119
131
|
|
120
132
|
yield(key).tap { |value| write(key, value, **options) } if block_given?
|
121
133
|
end
|
@@ -238,6 +250,15 @@ module AnyCache::Adapters
|
|
238
250
|
flushdb
|
239
251
|
end
|
240
252
|
|
253
|
+
# @param options [Hash]
|
254
|
+
# @return [void]
|
255
|
+
#
|
256
|
+
# @api private
|
257
|
+
# @since 0.4.0
|
258
|
+
def cleanup(**options)
|
259
|
+
# NOTE: manual removing is not suppored (redis doing this by itself)
|
260
|
+
end
|
261
|
+
|
241
262
|
# @param key [String]
|
242
263
|
# @param options [Hash]
|
243
264
|
# @return [Boolean]
|
@@ -18,15 +18,16 @@ module AnyCache::Adapters
|
|
18
18
|
def_delegators :driver, :mset
|
19
19
|
|
20
20
|
# @param key [String]
|
21
|
-
# @
|
21
|
+
# @option raw [Boolean]
|
22
22
|
# @return [Object]
|
23
23
|
#
|
24
24
|
# @api private
|
25
25
|
# @since 0.1.0
|
26
26
|
def read(key, **options)
|
27
|
-
raw = options.fetch(:raw,
|
27
|
+
raw = options.fetch(:raw, false)
|
28
|
+
value = get(key, raw: true)
|
28
29
|
|
29
|
-
|
30
|
+
raw ? value : detransform_value(value)
|
30
31
|
end
|
31
32
|
|
32
33
|
# @param keys [Array<String>]
|
@@ -43,24 +44,29 @@ module AnyCache::Adapters
|
|
43
44
|
# @param key [String]
|
44
45
|
# @param value [Object]
|
45
46
|
# @option expires_in [NilClass, Integer] Time in seconds
|
47
|
+
# @option raw [Boolean]
|
46
48
|
# @return [void]
|
47
49
|
#
|
48
50
|
# @api private
|
49
51
|
# @since 0.1.0
|
50
52
|
def write(key, value, **options)
|
51
53
|
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
|
52
|
-
raw = options.fetch(:raw,
|
54
|
+
raw = options.fetch(:raw, false)
|
55
|
+
value = transform_value(value) unless raw
|
53
56
|
|
54
|
-
expires_in ? setex(key, expires_in, value, raw:
|
57
|
+
expires_in ? setex(key, expires_in, value, raw: true) : set(key, value, raw: true)
|
55
58
|
end
|
56
59
|
|
57
60
|
# @param entries [Hash]
|
58
|
-
# @
|
61
|
+
# @option raw [Boolean]
|
59
62
|
# @return [void]
|
60
63
|
#
|
61
64
|
# @api private
|
62
65
|
# @since 0.3.0
|
63
66
|
def write_multi(entries, **options)
|
67
|
+
raw = options.fetch(:raw, false)
|
68
|
+
entries = transform_pairset(entries) unless raw
|
69
|
+
|
64
70
|
mset(*entries.to_a.flatten!, raw: true)
|
65
71
|
end
|
66
72
|
end
|
data/lib/any_cache/delegation.rb
CHANGED
@@ -40,7 +40,7 @@ module AnyCache::Delegation
|
|
40
40
|
AnyCache::Logging::Activity.log(
|
41
41
|
self, logger, activity: delegat, message:
|
42
42
|
"performed <#{delegat}> operation with " \
|
43
|
-
"
|
43
|
+
"attributes: #{args.inspect} and options: #{opts.inspect}."
|
44
44
|
) if logger
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.4.0
|
5
|
+
module AnyCache::Dumper
|
6
|
+
require_relative 'dumper/interface_access_mixin'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# @param hash [Hash]
|
10
|
+
# @return [Hash]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
# @since 0.4.0
|
14
|
+
def transform_hash(hash)
|
15
|
+
{}.tap do |entries|
|
16
|
+
hash.each_pair do |key, value|
|
17
|
+
entries[key] = dump(value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param hash [Hash]
|
23
|
+
# @return [Hash]
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
# @since 0.4.0
|
27
|
+
def detransform_hash(hash)
|
28
|
+
{}.tap do |entries|
|
29
|
+
hash.each_pair do |key, value|
|
30
|
+
entries[key] = load(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param value [Object]
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
# @api private
|
39
|
+
# @since 0.4.0
|
40
|
+
def dump(value)
|
41
|
+
return value if value.nil?
|
42
|
+
Zlib::Deflate.deflate(Marshal.dump(value))
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param value [String]
|
46
|
+
# @return [Object]
|
47
|
+
#
|
48
|
+
# @api private
|
49
|
+
# @since 0.4.0
|
50
|
+
def load(value)
|
51
|
+
return value if value.nil?
|
52
|
+
Marshal.load(Zlib::Inflate.inflate(value))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.4.0
|
5
|
+
module AnyCache::Dumper::InterfaceAccessMixin
|
6
|
+
# @param value [Object]
|
7
|
+
# @return [Object]
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
# @since 0.4.0
|
11
|
+
def transform_value(value)
|
12
|
+
AnyCache::Dumper.dump(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param value [Object]
|
16
|
+
# @return [Object]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.4.0
|
20
|
+
def detransform_value(value)
|
21
|
+
AnyCache::Dumper.load(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param pairset [Hash]
|
25
|
+
# @return [Hash]
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
# @since 0.4.0
|
29
|
+
def transform_pairset(pairset)
|
30
|
+
AnyCache::Dumper.transform_hash(pairset)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param pairset [Hash]
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
# @since 0.4.0
|
38
|
+
def detransform_pairset(pairset)
|
39
|
+
AnyCache::Dumper.detransform_hash(pairset)
|
40
|
+
end
|
41
|
+
end
|
data/lib/any_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: any_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.13'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.13'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,8 @@ files:
|
|
205
205
|
- lib/any_cache/drivers/dalli.rb
|
206
206
|
- lib/any_cache/drivers/redis.rb
|
207
207
|
- lib/any_cache/drivers/redis_store.rb
|
208
|
+
- lib/any_cache/dumper.rb
|
209
|
+
- lib/any_cache/dumper/interface_access_mixin.rb
|
208
210
|
- lib/any_cache/error.rb
|
209
211
|
- lib/any_cache/logging.rb
|
210
212
|
- lib/any_cache/logging/activity.rb
|
@@ -224,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
226
|
requirements:
|
225
227
|
- - ">="
|
226
228
|
- !ruby/object:Gem::Version
|
227
|
-
version: 2.3.
|
229
|
+
version: 2.3.8
|
228
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
231
|
requirements:
|
230
232
|
- - ">="
|