any_cache 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/CHANGELOG.md +15 -0
- data/README.md +240 -76
- data/any_cache.gemspec +1 -1
- data/bin/rspec +14 -2
- data/lib/any_cache/adapters/active_support_dalli_store.rb +219 -0
- data/lib/any_cache/adapters/active_support_mem_cache_store.rb +71 -16
- data/lib/any_cache/adapters/active_support_naive_store/operation.rb +6 -0
- data/lib/any_cache/adapters/active_support_naive_store.rb +79 -17
- data/lib/any_cache/adapters/active_support_redis_cache_store.rb +68 -17
- data/lib/any_cache/adapters/basic.rb +52 -10
- data/lib/any_cache/adapters/dalli.rb +81 -17
- data/lib/any_cache/adapters/delegator.rb +10 -0
- data/lib/any_cache/adapters/redis.rb +92 -18
- data/lib/any_cache/adapters/redis_store.rb +23 -0
- data/lib/any_cache/adapters.rb +4 -2
- data/lib/any_cache/delegation.rb +50 -0
- data/lib/any_cache/drivers/active_support_dalli_store.rb +25 -0
- data/lib/any_cache/drivers.rb +5 -0
- data/lib/any_cache/logging/activity.rb +27 -0
- data/lib/any_cache/logging/logger.rb +12 -0
- data/lib/any_cache/logging.rb +8 -0
- data/lib/any_cache/version.rb +1 -1
- data/lib/any_cache.rb +31 -15
- metadata +10 -4
@@ -39,9 +39,16 @@ module AnyCache::Adapters
|
|
39
39
|
# @since 0.1.0
|
40
40
|
MIN_DECRESEAD_VAL = 0
|
41
41
|
|
42
|
+
# @return [Array]
|
43
|
+
#
|
44
|
+
# @api private
|
45
|
+
# @since 0.3.0
|
46
|
+
READ_MULTI_EMPTY_KEYS_SET = [].freeze
|
47
|
+
|
42
48
|
# @since 0.1.0
|
43
49
|
def_delegators :driver,
|
44
50
|
:get,
|
51
|
+
:get_multi,
|
45
52
|
:set,
|
46
53
|
:incr,
|
47
54
|
:decr,
|
@@ -59,6 +66,25 @@ module AnyCache::Adapters
|
|
59
66
|
get(key)
|
60
67
|
end
|
61
68
|
|
69
|
+
# @param keys [Array<String>]
|
70
|
+
# @param options [Hash]
|
71
|
+
# @return [Hash]
|
72
|
+
#
|
73
|
+
# @api private
|
74
|
+
# @since 0.3.0
|
75
|
+
def read_multi(*keys, **options)
|
76
|
+
get_multi(*keys).tap do |res|
|
77
|
+
res.merge!(Hash[(keys - res.keys).zip(READ_MULTI_EMPTY_KEYS_SET)])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param key [String]
|
82
|
+
# @param value [Object]
|
83
|
+
# @option expires_in [Integer]
|
84
|
+
# @return [void]
|
85
|
+
#
|
86
|
+
# @api private
|
87
|
+
# @since 0.1.0
|
62
88
|
def write(key, value, **options)
|
63
89
|
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
|
64
90
|
raw = options.fetch(:raw, true)
|
@@ -66,6 +92,51 @@ module AnyCache::Adapters
|
|
66
92
|
set(key, value, expires_in, raw: raw)
|
67
93
|
end
|
68
94
|
|
95
|
+
# @param entries [Hash]
|
96
|
+
# @param options [Hash]
|
97
|
+
# @return [void]
|
98
|
+
#
|
99
|
+
# @api private
|
100
|
+
# @since 0.3.0
|
101
|
+
def write_multi(entries, **options)
|
102
|
+
raw = options.fetch(:raw, true)
|
103
|
+
|
104
|
+
entries.each_pair { |key, value| write(key, value, raw: raw) }
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param key [String]
|
108
|
+
# @param fallback [Proc]
|
109
|
+
# @option expires_in [Integer]
|
110
|
+
# @option force [Boolean, Proc]
|
111
|
+
# @return [Object]
|
112
|
+
#
|
113
|
+
# @api private
|
114
|
+
# @since 0.2.0
|
115
|
+
def fetch(key, **options, &fallback)
|
116
|
+
force_rewrite = options.fetch(:force, false)
|
117
|
+
force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call)
|
118
|
+
|
119
|
+
# NOTE: can conflict with :cache_nils Dalli::Client's config
|
120
|
+
read(key).tap { |value| return value if value } unless force_rewrite
|
121
|
+
|
122
|
+
yield(key).tap { |value| write(key, value, **options) } if block_given?
|
123
|
+
end
|
124
|
+
|
125
|
+
# @param keys [Array<String>]
|
126
|
+
# @param fallback [Proc]
|
127
|
+
# @option force [Boolean, Proc]
|
128
|
+
# @option expires_in [Integer]
|
129
|
+
# @return [Hash]
|
130
|
+
#
|
131
|
+
# @api private
|
132
|
+
# @since 0.3.0
|
133
|
+
def fetch_multi(*keys, **options, &fallback)
|
134
|
+
# TODO: think about multi-thread approach
|
135
|
+
keys.each_with_object({}) do |key, dataset|
|
136
|
+
dataset[key] = fetch(key, **options, &fallback)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
69
140
|
# @param key [String]
|
70
141
|
# @param options [Hash]
|
71
142
|
# @return [void]
|
@@ -76,6 +147,16 @@ module AnyCache::Adapters
|
|
76
147
|
driver.delete(key)
|
77
148
|
end
|
78
149
|
|
150
|
+
# @param pattern [String, Regexp]
|
151
|
+
# @param options [Hash]
|
152
|
+
# @return [void]
|
153
|
+
#
|
154
|
+
# @api private
|
155
|
+
# @since 0.3.0
|
156
|
+
def delete_matched(pattern, **options)
|
157
|
+
# TODO: make it real >:]
|
158
|
+
end
|
159
|
+
|
79
160
|
# @param key [String]
|
80
161
|
# @param amount [Integer]
|
81
162
|
# @option expires_in [NilClass, Integer]
|
@@ -147,22 +228,5 @@ module AnyCache::Adapters
|
|
147
228
|
def exist?(key, **options)
|
148
229
|
!get(key).nil? # NOTE: can conflict with :cache_nils Dalli::Client's config
|
149
230
|
end
|
150
|
-
|
151
|
-
# @param key [String]
|
152
|
-
# @option expires_in [Integer]
|
153
|
-
# @option force [Boolean]
|
154
|
-
# @return [Object]
|
155
|
-
#
|
156
|
-
# @api private
|
157
|
-
# @since 0.2.0
|
158
|
-
def fetch(key, **options)
|
159
|
-
force_rewrite = options.fetch(:force, false)
|
160
|
-
force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call)
|
161
|
-
|
162
|
-
# NOTE: can conflict with :cache_nils Dalli::Client's config
|
163
|
-
read(key).tap { |value| return value if value } unless force_rewrite
|
164
|
-
|
165
|
-
yield.tap { |value| write(key, value, **options) } if block_given?
|
166
|
-
end
|
167
231
|
end
|
168
232
|
end
|
@@ -10,10 +10,15 @@ module AnyCache::Adapters
|
|
10
10
|
#
|
11
11
|
# @api private
|
12
12
|
# @since 0.1.0
|
13
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
13
14
|
def supported_driver?(driver)
|
14
15
|
driver.respond_to?(:read) &&
|
16
|
+
driver.respond_to?(:read_multi) &&
|
15
17
|
driver.respond_to?(:write) &&
|
18
|
+
driver.respond_to?(:write_multi) &&
|
19
|
+
driver.respond_to?(:fetch_multi) &&
|
16
20
|
driver.respond_to?(:delete) &&
|
21
|
+
driver.respond_to?(:delete_matched) &&
|
17
22
|
driver.respond_to?(:increment) &&
|
18
23
|
driver.respond_to?(:decrement) &&
|
19
24
|
driver.respond_to?(:expire) &&
|
@@ -22,13 +27,18 @@ module AnyCache::Adapters
|
|
22
27
|
driver.respond_to?(:exist?) &&
|
23
28
|
driver.respond_to?(:fetch)
|
24
29
|
end
|
30
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
25
31
|
end
|
26
32
|
|
27
33
|
# @since 0.1.0
|
28
34
|
def_delegators :driver,
|
29
35
|
:read,
|
36
|
+
:read_multi,
|
30
37
|
:write,
|
38
|
+
:write_multi,
|
39
|
+
:fetch_multi,
|
31
40
|
:delete,
|
41
|
+
:delete_matched,
|
32
42
|
:increment,
|
33
43
|
:decrement,
|
34
44
|
:expire,
|
@@ -33,6 +33,18 @@ module AnyCache::Adapters
|
|
33
33
|
# @since 0.1.0
|
34
34
|
DEFAULT_INCR_DECR_AMOUNT = 1
|
35
35
|
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
# @api private
|
39
|
+
# @since 0.3.0
|
40
|
+
DELETE_MATCHED_CURSOR_START = '0'
|
41
|
+
|
42
|
+
# @return [Integer]
|
43
|
+
#
|
44
|
+
# @api private
|
45
|
+
# @since 0.3.0
|
46
|
+
DELETE_MATCHED_BATCH_SIZE = 10
|
47
|
+
|
36
48
|
# @since 0.1.0
|
37
49
|
def_delegators :driver,
|
38
50
|
:get,
|
@@ -43,7 +55,10 @@ module AnyCache::Adapters
|
|
43
55
|
:decrby,
|
44
56
|
:pipelined,
|
45
57
|
:flushdb,
|
46
|
-
:exists
|
58
|
+
:exists,
|
59
|
+
:mapped_mget,
|
60
|
+
:mapped_mset,
|
61
|
+
:scan
|
47
62
|
|
48
63
|
# @param key [String]
|
49
64
|
# @param options [Hash]
|
@@ -55,6 +70,16 @@ module AnyCache::Adapters
|
|
55
70
|
get(key)
|
56
71
|
end
|
57
72
|
|
73
|
+
# @param keys [Array<String>]
|
74
|
+
# @param options [Hash]
|
75
|
+
# @return [Hash]
|
76
|
+
#
|
77
|
+
# @api private
|
78
|
+
# @since 0.3.0
|
79
|
+
def read_multi(*keys, **options)
|
80
|
+
mapped_mget(*keys)
|
81
|
+
end
|
82
|
+
|
58
83
|
# @param key [String]
|
59
84
|
# @param value [Object]
|
60
85
|
# @option expires_in [NilClass, Integer] Time in seconds
|
@@ -68,6 +93,47 @@ module AnyCache::Adapters
|
|
68
93
|
expires_in ? setex(key, expires_in, value) : set(key, value)
|
69
94
|
end
|
70
95
|
|
96
|
+
# @param entries [Hash]
|
97
|
+
# @param options [Hash]
|
98
|
+
# @return [void]
|
99
|
+
#
|
100
|
+
# @api private
|
101
|
+
# @since 0.3.0
|
102
|
+
def write_multi(entries, **options)
|
103
|
+
mapped_mset(entries)
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param key [String]
|
107
|
+
# @option expires_in [Integer]
|
108
|
+
# @option force [Boolean]
|
109
|
+
# @return [Object]
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
# @since 0.2.0
|
113
|
+
def fetch(key, **options, &fallback)
|
114
|
+
force_rewrite = options.fetch(:force, false)
|
115
|
+
force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call)
|
116
|
+
|
117
|
+
# NOTE: think about #pipelined
|
118
|
+
read(key).tap { |value| return value if value } unless force_rewrite
|
119
|
+
|
120
|
+
yield(key).tap { |value| write(key, value, **options) } if block_given?
|
121
|
+
end
|
122
|
+
|
123
|
+
# @param keys [Array<string>]
|
124
|
+
# @param options [Hash]
|
125
|
+
# @param fallback [Proc]
|
126
|
+
# @return [Hash]
|
127
|
+
#
|
128
|
+
# @api private
|
129
|
+
# @since 0.3.0
|
130
|
+
def fetch_multi(*keys, **options, &fallback)
|
131
|
+
# TODO: think about multi-thread approach
|
132
|
+
keys.each_with_object({}) do |key, dataset|
|
133
|
+
dataset[key] = fetch(key, **options, &fallback)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
71
137
|
# @param key [String]
|
72
138
|
# @param options [Hash]
|
73
139
|
# @return [void]
|
@@ -78,6 +144,31 @@ module AnyCache::Adapters
|
|
78
144
|
del(key)
|
79
145
|
end
|
80
146
|
|
147
|
+
# @param pattern [String, Regexp]
|
148
|
+
# @param options [Hash]
|
149
|
+
# @return [void]
|
150
|
+
#
|
151
|
+
# @api private
|
152
|
+
# @since 0.3.0
|
153
|
+
def delete_matched(pattern, **options)
|
154
|
+
cursor = DELETE_MATCHED_CURSOR_START
|
155
|
+
|
156
|
+
case pattern
|
157
|
+
when String
|
158
|
+
loop do
|
159
|
+
cursor, keys = scan(cursor, match: pattern, count: DELETE_MATCHED_BATCH_SIZE)
|
160
|
+
del(keys)
|
161
|
+
break if cursor == DELETE_MATCHED_CURSOR_START
|
162
|
+
end
|
163
|
+
when Regexp
|
164
|
+
loop do
|
165
|
+
cursor, keys = scan(cursor, count: DELETE_MATCHED_BATCH_SIZE)
|
166
|
+
del(keys.grep(pattern))
|
167
|
+
break if cursor == DELETE_MATCHED_CURSOR_START
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
81
172
|
# @param key [String]
|
82
173
|
# @param amount [Integer]
|
83
174
|
# @option expires_in [NilClass, Integer] Time in seconds
|
@@ -156,22 +247,5 @@ module AnyCache::Adapters
|
|
156
247
|
def exist?(key, **options)
|
157
248
|
exists(key)
|
158
249
|
end
|
159
|
-
|
160
|
-
# @param key [String]
|
161
|
-
# @option expires_in [Integer]
|
162
|
-
# @option force [Boolean]
|
163
|
-
# @return [Object]
|
164
|
-
#
|
165
|
-
# @api private
|
166
|
-
# @since 0.2.0
|
167
|
-
def fetch(key, **options)
|
168
|
-
force_rewrite = options.fetch(:force, false)
|
169
|
-
force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call)
|
170
|
-
|
171
|
-
# NOTE: think about #pipelined
|
172
|
-
read(key).tap { |value| return value if value } unless force_rewrite
|
173
|
-
|
174
|
-
yield.tap { |value| write(key, value, **options) } if block_given?
|
175
|
-
end
|
176
250
|
end
|
177
251
|
end
|
@@ -15,6 +15,8 @@ module AnyCache::Adapters
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def_delegators :driver, :mset
|
19
|
+
|
18
20
|
# @param key [String]
|
19
21
|
# @param options [Hash]
|
20
22
|
# @return [Object]
|
@@ -27,6 +29,17 @@ module AnyCache::Adapters
|
|
27
29
|
get(key, raw: raw)
|
28
30
|
end
|
29
31
|
|
32
|
+
# @param keys [Array<String>]
|
33
|
+
# @param options [Hash]
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
# @since 0.3.0
|
38
|
+
def read_multi(*keys, **options)
|
39
|
+
# NOTE: cant use Redis::Store#mget cuz it has some marshalling errors :(
|
40
|
+
Hash[keys.zip(keys.map { |key| read(key, **options) })]
|
41
|
+
end
|
42
|
+
|
30
43
|
# @param key [String]
|
31
44
|
# @param value [Object]
|
32
45
|
# @option expires_in [NilClass, Integer] Time in seconds
|
@@ -40,5 +53,15 @@ module AnyCache::Adapters
|
|
40
53
|
|
41
54
|
expires_in ? setex(key, expires_in, value, raw: raw) : set(key, value, raw: raw)
|
42
55
|
end
|
56
|
+
|
57
|
+
# @param entries [Hash]
|
58
|
+
# @param options [Hash]
|
59
|
+
# @return [void]
|
60
|
+
#
|
61
|
+
# @api private
|
62
|
+
# @since 0.3.0
|
63
|
+
def write_multi(entries, **options)
|
64
|
+
mset(*entries.to_a.flatten!, raw: true)
|
65
|
+
end
|
43
66
|
end
|
44
67
|
end
|
data/lib/any_cache/adapters.rb
CHANGED
@@ -13,6 +13,7 @@ module AnyCache::Adapters
|
|
13
13
|
require_relative 'adapters/active_support_redis_cache_store'
|
14
14
|
require_relative 'adapters/active_support_memory_store'
|
15
15
|
require_relative 'adapters/active_support_mem_cache_store'
|
16
|
+
require_relative 'adapters/active_support_dalli_store'
|
16
17
|
|
17
18
|
class << self
|
18
19
|
# @param driver [Object]
|
@@ -22,7 +23,7 @@ module AnyCache::Adapters
|
|
22
23
|
#
|
23
24
|
# @api private
|
24
25
|
# @since 0.1.0
|
25
|
-
# rubocop:disable Metrics/LineLength
|
26
|
+
# rubocop:disable Metrics/LineLength, Metrics/AbcSize
|
26
27
|
def build(driver)
|
27
28
|
case
|
28
29
|
when RedisStore.supported_driver?(driver) then RedisStore.new(driver)
|
@@ -32,11 +33,12 @@ module AnyCache::Adapters
|
|
32
33
|
when ActiveSupportMemoryStore.supported_driver?(driver) then ActiveSupportMemoryStore.new(driver)
|
33
34
|
when ActiveSupportFileStore.supported_driver?(driver) then ActiveSupportFileStore.new(driver)
|
34
35
|
when ActiveSupportMemCacheStore.supported_driver?(driver) then ActiveSupportMemCacheStore.new(driver)
|
36
|
+
when ActiveSupportDalliStore.supported_driver?(driver) then ActiveSupportDalliStore.new(driver)
|
35
37
|
when Delegator.supported_driver?(driver) then Delegator.new(driver)
|
36
38
|
else
|
37
39
|
raise AnyCache::UnsupportedDriverError
|
38
40
|
end
|
39
41
|
end
|
40
|
-
# rubocop:enable Metrics/LineLength
|
42
|
+
# rubocop:enable Metrics/LineLength, Metrics/AbcSize
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.3.0
|
5
|
+
module AnyCache::Delegation
|
6
|
+
class << self
|
7
|
+
# @param base_klass [Class]
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
# @since 0.3.0
|
12
|
+
def included(base_klass)
|
13
|
+
base_klass.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @api private
|
18
|
+
# @since 0.3.0
|
19
|
+
module ClassMethods
|
20
|
+
# @param receiver [Symbol, String]
|
21
|
+
# @param delegators [Array<Symbol, String>]
|
22
|
+
# @return [void]
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
# @since 0.3.0
|
26
|
+
def def_loggable_delegators(receiver, *delegators)
|
27
|
+
delegators.each { |delegat| def_loggable_delegator(receiver, delegat) }
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param receiver [Symbol, String]
|
31
|
+
# @param delegat [Symbol, String]
|
32
|
+
# @return [void]
|
33
|
+
#
|
34
|
+
# @api private
|
35
|
+
# @since 0.3.0
|
36
|
+
def def_loggable_delegator(receiver, delegat)
|
37
|
+
define_method(delegat) do |*args, **opts, &block|
|
38
|
+
send(receiver).send(delegat, *args, **opts, &block).tap do
|
39
|
+
shared_config[:logger].tap do |logger|
|
40
|
+
AnyCache::Logging::Activity.log(
|
41
|
+
self, logger, activity: delegat, message:
|
42
|
+
"performed <#{delegat}> operation with " \
|
43
|
+
"params: #{args.inspect} and options: #{opts.inspect}."
|
44
|
+
) if logger
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnyCache::Drivers::ActiveSupportDalliStore
|
4
|
+
class << self
|
5
|
+
# @param driver [::ActiveSupport::Cache::DalliStore]
|
6
|
+
# @return [Boolean]
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 0.3.0
|
10
|
+
def supported_source?(driver)
|
11
|
+
defined?(::Dalli) &&
|
12
|
+
defined?(::ActiveSupport::Cache::DalliStore) &&
|
13
|
+
driver.is_a?(::ActiveSupport::Cache::DalliStore)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param settings [Qonfig:Settings]
|
17
|
+
# @return [::ActiveSupport::Cache::DalliStore]
|
18
|
+
#
|
19
|
+
# @api private
|
20
|
+
# @since 0.3.0
|
21
|
+
def build(settings)
|
22
|
+
::ActiveSupport::Cache::DalliStore.new([Array(settings.servers), settings.options])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/any_cache/drivers.rb
CHANGED
@@ -10,6 +10,7 @@ module AnyCache::Drivers
|
|
10
10
|
require_relative 'drivers/active_support_memory_store'
|
11
11
|
require_relative 'drivers/active_support_redis_cache_store'
|
12
12
|
require_relative 'drivers/active_support_mem_cache_store'
|
13
|
+
require_relative 'drivers/active_support_dalli_store'
|
13
14
|
|
14
15
|
class << self
|
15
16
|
# @param config [Qonfig::DataSet]
|
@@ -19,6 +20,7 @@ module AnyCache::Drivers
|
|
19
20
|
#
|
20
21
|
# @api private
|
21
22
|
# @since 0.2.0
|
23
|
+
# rubocop:disable Metrics/AbcSize
|
22
24
|
def build(config)
|
23
25
|
driver = config[:driver]
|
24
26
|
|
@@ -37,9 +39,12 @@ module AnyCache::Drivers
|
|
37
39
|
ActiveSupportRedisCacheStore.build(config[:as_redis_cache_store])
|
38
40
|
when :as_mem_cache_store
|
39
41
|
ActiveSupportMemCacheStore.build(config[:as_mem_cache_store])
|
42
|
+
when :as_dalli_store
|
43
|
+
ActiveSupportDalliStore.build(config[:as_dalli_store])
|
40
44
|
else
|
41
45
|
raise AnyCache::UnsupportedDriverError
|
42
46
|
end
|
43
47
|
end
|
48
|
+
# rubocop:enable Metrics/AbcSize
|
44
49
|
end
|
45
50
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.3.0
|
5
|
+
module AnyCache::Logging::Activity
|
6
|
+
# @return [String]
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 0.3.0
|
10
|
+
ANONYMOUS_CACHER_CLASS_NAME = '<__anonymous_cache__>'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# @param cacher [AnyCache]
|
14
|
+
# @param logger [::Logger]
|
15
|
+
# @option activity [String, NilClass]
|
16
|
+
# @option message [String, NillClass]
|
17
|
+
# @return [void]
|
18
|
+
#
|
19
|
+
# @api private
|
20
|
+
# @since 0.3.0
|
21
|
+
def log(cacher, logger, activity: nil, message: nil)
|
22
|
+
cacher = cacher.class.name || ANONYMOUS_CACHER_CLASS_NAME
|
23
|
+
progname = "[AnyCache<#{cacher}>/Activity<#{activity}>]"
|
24
|
+
logger.add(logger.level, message, progname)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/any_cache/version.rb
CHANGED
data/lib/any_cache.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
3
4
|
require 'qonfig'
|
4
5
|
require 'securerandom'
|
5
6
|
require 'concurrent/atomic/reentrant_read_write_lock'
|
@@ -11,17 +12,22 @@ class AnyCache
|
|
11
12
|
require_relative 'any_cache/error'
|
12
13
|
require_relative 'any_cache/drivers'
|
13
14
|
require_relative 'any_cache/adapters'
|
14
|
-
|
15
|
-
|
16
|
-
extend Forwardable
|
15
|
+
require_relative 'any_cache/logging'
|
16
|
+
require_relative 'any_cache/delegation'
|
17
17
|
|
18
18
|
# @since 0.2.0
|
19
19
|
include Qonfig::Configurable
|
20
20
|
|
21
|
+
# @since 0.3.0
|
22
|
+
include Delegation
|
23
|
+
|
21
24
|
# @since 0.2.0
|
25
|
+
# rubocop:disable Metrics/BlockLength
|
22
26
|
configuration do
|
23
27
|
setting :driver
|
24
28
|
|
29
|
+
setting :logger, Logging::Logger.new(STDOUT)
|
30
|
+
|
25
31
|
setting :redis do
|
26
32
|
setting :options, {}
|
27
33
|
end
|
@@ -52,7 +58,13 @@ class AnyCache
|
|
52
58
|
setting :servers, nil
|
53
59
|
setting :options, {}
|
54
60
|
end
|
61
|
+
|
62
|
+
setting :as_dalli_store do
|
63
|
+
setting :servers, nil
|
64
|
+
setting :options, {}
|
65
|
+
end
|
55
66
|
end
|
67
|
+
# rubocop:enable Metrics/BlockLength
|
56
68
|
|
57
69
|
class << self
|
58
70
|
# @param driver [Object]
|
@@ -66,18 +78,22 @@ class AnyCache
|
|
66
78
|
end
|
67
79
|
|
68
80
|
# @api public
|
69
|
-
# @since 0.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
# @since 0.3.0
|
82
|
+
def_loggable_delegators :adapter,
|
83
|
+
:read,
|
84
|
+
:read_multi,
|
85
|
+
:write,
|
86
|
+
:write_multi,
|
87
|
+
:fetch,
|
88
|
+
:fetch_multi,
|
89
|
+
:delete,
|
90
|
+
:delete_matched,
|
91
|
+
:increment,
|
92
|
+
:decrement,
|
93
|
+
:expire,
|
94
|
+
:persist,
|
95
|
+
:clear,
|
96
|
+
:exist?
|
81
97
|
|
82
98
|
# @return [AnyCache::Adapters::Basic]
|
83
99
|
#
|
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.3.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-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.9'
|
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.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- gemfiles/redis_store.gemfile
|
168
168
|
- lib/any_cache.rb
|
169
169
|
- lib/any_cache/adapters.rb
|
170
|
+
- lib/any_cache/adapters/active_support_dalli_store.rb
|
170
171
|
- lib/any_cache/adapters/active_support_file_store.rb
|
171
172
|
- lib/any_cache/adapters/active_support_file_store/decrement.rb
|
172
173
|
- lib/any_cache/adapters/active_support_file_store/expire.rb
|
@@ -194,7 +195,9 @@ files:
|
|
194
195
|
- lib/any_cache/adapters/delegator.rb
|
195
196
|
- lib/any_cache/adapters/redis.rb
|
196
197
|
- lib/any_cache/adapters/redis_store.rb
|
198
|
+
- lib/any_cache/delegation.rb
|
197
199
|
- lib/any_cache/drivers.rb
|
200
|
+
- lib/any_cache/drivers/active_support_dalli_store.rb
|
198
201
|
- lib/any_cache/drivers/active_support_file_store.rb
|
199
202
|
- lib/any_cache/drivers/active_support_mem_cache_store.rb
|
200
203
|
- lib/any_cache/drivers/active_support_memory_store.rb
|
@@ -203,6 +206,9 @@ files:
|
|
203
206
|
- lib/any_cache/drivers/redis.rb
|
204
207
|
- lib/any_cache/drivers/redis_store.rb
|
205
208
|
- lib/any_cache/error.rb
|
209
|
+
- lib/any_cache/logging.rb
|
210
|
+
- lib/any_cache/logging/activity.rb
|
211
|
+
- lib/any_cache/logging/logger.rb
|
206
212
|
- lib/any_cache/version.rb
|
207
213
|
homepage: https://github.com/0exp/any_cache
|
208
214
|
licenses:
|