any_cache 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCache::Adapters
4
+ # @api private
5
+ # @since 0.2.0
6
+ class ActiveSupportMemCacheStore < Basic
7
+ # NOTE: think about locks (Concurrent::ReentrantReadWriteLock)
8
+
9
+ class << self
10
+ # @param driver [Object]
11
+ # @retunr [Boolean]
12
+ #
13
+ # @api private
14
+ # @since 0.2.0
15
+ def supported_driver?(driver)
16
+ AnyCache::Drivers::ActiveSupportMemCacheStore.supported_source?(driver)
17
+ end
18
+ end
19
+
20
+ # @return [NilClass]
21
+ #
22
+ # @api private
23
+ # @since 0.2.0
24
+ NO_EXPIRATION_TTL = nil
25
+
26
+ # @return [Integer]
27
+ #
28
+ # @api private
29
+ # @since 0.2.0
30
+ DEAD_TTL = 0
31
+
32
+ # @return [Integer]
33
+ #
34
+ # @api private
35
+ # @since 0.2.0
36
+ DEFAULT_INCR_DECR_AMOUNT = 1
37
+
38
+ # @return [Integer]
39
+ #
40
+ # @api private
41
+ # @since 0.2.0
42
+ INITIAL_DECREMNETED_VALUE = 0
43
+
44
+ # @since 0.2.0
45
+ def_delegators :driver, :delete, :clear
46
+
47
+ # @param key
48
+ # @param options [Hash]
49
+ # @return [Object]
50
+ #
51
+ # @api private
52
+ # @since 0.2.0
53
+ def read(key, **options)
54
+ raw = options.fetch(:raw, true)
55
+
56
+ driver.read(key, raw: raw)
57
+ end
58
+
59
+ # @param key [String]
60
+ # @param value [Object]
61
+ # @option expires_in [NilClass, Integer] Time in seconds
62
+ # @return [void]
63
+ #
64
+ # @api private
65
+ # @sicne 0.2.0
66
+ def write(key, value, **options)
67
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
68
+ raw = options.fetch(:raw, true)
69
+
70
+ driver.write(key, value, expires_in: expires_in, raw: raw)
71
+ end
72
+
73
+ # @param key [String]
74
+ # @param amount [Integer]
75
+ # @options expires_in [Integer]
76
+ # @return [Integer, Float]
77
+ #
78
+ # @api private
79
+ # @since 0.2.0
80
+ def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
81
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
82
+
83
+ unless exist?(key)
84
+ write(key, amount, expires_in: expires_in) && amount
85
+ else
86
+ driver.increment(key, amount).tap do
87
+ expire(key, expires_in: expires_in) if expires_in
88
+ end
89
+ end
90
+ end
91
+
92
+ # @param key [String]
93
+ # @param amount [Integer]
94
+ # @option expires_in [Integer]
95
+ # @return [Integer, Float]
96
+ #
97
+ # @api private
98
+ # @since 0.2.0
99
+ def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
100
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
101
+
102
+ unless exist?(key)
103
+ # NOTE: Dalli::Client can't decrement:
104
+ # - non-raw values;
105
+ # - values lower than zero;
106
+ # - empty entries;
107
+ write(key, INITIAL_DECREMNETED_VALUE, expires_in: expires_in) && INITIAL_DECREMNETED_VALUE
108
+ else
109
+ driver.decrement(key, amount).tap do
110
+ expire(key, expires_in: expires_in) if expires_in
111
+ end
112
+ end
113
+ end
114
+
115
+ # @param key [String]
116
+ # @option expires_in [Integer]
117
+ # @return [void]
118
+ #
119
+ # @api private
120
+ # @since 0.2.0
121
+ def expire(key, expires_in: DEAD_TTL)
122
+ read(key).tap do |value|
123
+ is_alive = expires_in ? expires_in.positive? : false
124
+ is_alive ? write(key, value, expires_in: expires_in) : delete(key)
125
+ end
126
+ end
127
+
128
+ # @param key [String]
129
+ # @param options [Hash]
130
+ # @return [void]
131
+ #
132
+ # @api private
133
+ # @sicne 0.2.0
134
+ def persist(key, **options)
135
+ read(key).tap { |value| write(key, value) }
136
+ end
137
+
138
+ # @param key [String]
139
+ # @param options [Hash]
140
+ # @return [Boolean]
141
+ #
142
+ # @api private
143
+ # @since 0.2.0
144
+ def exist?(key, **options)
145
+ driver.exist?(key)
146
+ end
147
+
148
+ # @param key [String]
149
+ # @option expires_in [Integer]
150
+ # @option force [Boolean]
151
+ # @return [Object]
152
+ #
153
+ # @api private
154
+ # @since 0.2.0
155
+ def fetch(key, **options, &block)
156
+ force_rewrite = options.fetch(:force, false)
157
+ force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call)
158
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
159
+
160
+ driver.fetch(key, force: force_rewrite, expires_in: expires_in, &block)
161
+ end
162
+ end
163
+ end
@@ -18,8 +18,7 @@ module AnyCache::Adapters
18
18
  # @api private
19
19
  # @since 0.1.0
20
20
  def supported_driver?(driver)
21
- defined?(::ActiveSupport::Cache::MemoryStore) &&
22
- driver.is_a?(::ActiveSupport::Cache::MemoryStore)
21
+ AnyCache::Drivers::ActiveSupportMemoryStore.supported_source?(driver)
23
22
  end
24
23
  end
25
24
  end
@@ -118,6 +118,33 @@ module AnyCache::Adapters
118
118
  lock.with_write_lock { pers_operation.call(key) }
119
119
  end
120
120
 
121
+ # @param key [String]
122
+ # @param options [Hash]
123
+ # @return [Boolean]
124
+ #
125
+ # @api private
126
+ # @since 0.2.0
127
+ def exist?(key, **options)
128
+ lock.with_read_lock { super }
129
+ end
130
+
131
+ # @param key [String]
132
+ # @option expires_in [Integer]
133
+ # @option force [Boolean]
134
+ # @return [Object]
135
+ #
136
+ # @api private
137
+ # @since 0.2.0
138
+ def fetch(key, **options, &block)
139
+ lock.with_write_lock do
140
+ force_rewrite = options.fetch(:force, false)
141
+ force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call)
142
+ expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)
143
+
144
+ super(key, force: force_rewrite, expires_in: expires_in, &block)
145
+ end
146
+ end
147
+
121
148
  private
122
149
 
123
150
  # @return [Concurrent::ReentrantReadWriteLock]
@@ -145,6 +172,9 @@ module AnyCache::Adapters
145
172
  attr_reader :expr_operation
146
173
 
147
174
  # @return [Operation::Persist]
175
+ #
176
+ # @api private
177
+ # @since 0.1.0
148
178
  attr_reader :pers_operation
149
179
  end
150
180
  end
@@ -4,7 +4,7 @@ module AnyCache::Adapters
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  class ActiveSupportRedisCacheStore < Basic
7
- # TODO: think about locks
7
+ # TODO: think about locks (Concurrent::ReentrantReadWriteLock)
8
8
 
9
9
  class << self
10
10
  # @param driver [Object]
@@ -13,9 +13,7 @@ module AnyCache::Adapters
13
13
  # @api private
14
14
  # @since 0.1.0
15
15
  def supported_driver?(driver)
16
- defined?(::Redis) &&
17
- defined?(::ActiveSupport::Cache::RedisCacheStore) &&
18
- driver.is_a?(::ActiveSupport::Cache::RedisCacheStore)
16
+ AnyCache::Drivers::ActiveSupportRedisCacheStore.supported_source?(driver)
19
17
  end
20
18
  end
21
19
 
@@ -47,7 +45,9 @@ module AnyCache::Adapters
47
45
  # @api private
48
46
  # @since 0.1.0
49
47
  def read(key, **options)
50
- driver.read(key, raw: true)
48
+ raw = options.fetch(:raw, true)
49
+
50
+ driver.read(key, raw: raw)
51
51
  end
52
52
 
53
53
  # @param key [String]
@@ -59,8 +59,9 @@ module AnyCache::Adapters
59
59
  # @since 0.1.0
60
60
  def write(key, value, **options)
61
61
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
62
+ raw = options.fetch(:raw, true)
62
63
 
63
- driver.write(key, value, expires_in: expires_in, raw: true)
64
+ driver.write(key, value, expires_in: expires_in, raw: raw)
64
65
  end
65
66
 
66
67
  # @param key [String]
@@ -72,9 +73,8 @@ module AnyCache::Adapters
72
73
  # @since 0.1.0
73
74
  def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
74
75
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
75
- is_initial = expires_in && !read(key)
76
76
 
77
- if is_initial
77
+ unless exist?(key)
78
78
  write(key, amount, expires_in: expires_in) && amount
79
79
  else
80
80
  driver.increment(key, amount).tap do
@@ -92,9 +92,8 @@ module AnyCache::Adapters
92
92
  # @since 0.1.0
93
93
  def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
94
94
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
95
- is_initial = expires_in && !read(key)
96
95
 
97
- if is_initial
96
+ unless exist?(key)
98
97
  write(key, -amount, expires_in: expires_in) && -amount
99
98
  else
100
99
  driver.decrement(key, amount).tap do
@@ -125,5 +124,30 @@ module AnyCache::Adapters
125
124
  def persist(key, **options)
126
125
  read(key).tap { |value| write(key, value) }
127
126
  end
127
+
128
+ # @param key [String]
129
+ # @param options [Hash]
130
+ # @return [Boolean]
131
+ #
132
+ # @api private
133
+ # @since 0.2.0
134
+ def exist?(key, **options)
135
+ driver.exist?(key)
136
+ end
137
+
138
+ # @param key [String]
139
+ # @option expires_in [Integer]
140
+ # @option force [Boolean]
141
+ # @return [Object]
142
+ #
143
+ # @api private
144
+ # @since 0.2.0
145
+ def fetch(key, **options, &block)
146
+ force_rewrite = options.fetch(:force, false)
147
+ force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call)
148
+ expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
149
+
150
+ driver.fetch(key, force: force_rewrite, expires_in: expires_in, &block)
151
+ end
128
152
  end
129
153
  end
@@ -114,5 +114,25 @@ module AnyCache::Adapters
114
114
  def clear(**options)
115
115
  raise NotImplementedError
116
116
  end
117
+
118
+ # @param key [String]
119
+ # @param options [Hash]
120
+ # @return [Boolean]
121
+ #
122
+ # @api private
123
+ # @since 0.2.0
124
+ def exist?(key, **options)
125
+ raise NotImplementedError
126
+ end
127
+
128
+ # @param key [String]
129
+ # @param options [Hash]
130
+ # @return [Object]
131
+ #
132
+ # @api private
133
+ # @since 0.2.0
134
+ def fetch(key, **options, &block)
135
+ raise NotImplementedError
136
+ end
117
137
  end
118
138
  end
@@ -11,7 +11,7 @@ module AnyCache::Adapters
11
11
  # @api private
12
12
  # @since 0.1.0
13
13
  def supported_driver?(driver)
14
- defined?(::Dalli::Client) && driver.is_a?(::Dalli::Client)
14
+ AnyCache::Drivers::Dalli.supported_source?(driver)
15
15
  end
16
16
  end
17
17
 
@@ -61,8 +61,9 @@ module AnyCache::Adapters
61
61
 
62
62
  def write(key, value, **options)
63
63
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
64
+ raw = options.fetch(:raw, true)
64
65
 
65
- set(key, value, expires_in, raw: true)
66
+ set(key, value, expires_in, raw: raw)
66
67
  end
67
68
 
68
69
  # @param key [String]
@@ -136,5 +137,32 @@ module AnyCache::Adapters
136
137
  def clear(**options)
137
138
  flush(0) # NOTE: 0 is a flush delay
138
139
  end
140
+
141
+ # @param key [String]
142
+ # @param options [Hash]
143
+ # @return [Boolean]
144
+ #
145
+ # @api private
146
+ # @since 0.2.0
147
+ def exist?(key, **options)
148
+ !get(key).nil? # NOTE: can conflict with :cache_nils Dalli::Client's config
149
+ 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
139
167
  end
140
168
  end
@@ -18,7 +18,9 @@ module AnyCache::Adapters
18
18
  driver.respond_to?(:decrement) &&
19
19
  driver.respond_to?(:expire) &&
20
20
  driver.respond_to?(:persist) &&
21
- driver.respond_to?(:clear)
21
+ driver.respond_to?(:clear) &&
22
+ driver.respond_to?(:exist?) &&
23
+ driver.respond_to?(:fetch)
22
24
  end
23
25
  end
24
26
 
@@ -31,6 +33,8 @@ module AnyCache::Adapters
31
33
  :decrement,
32
34
  :expire,
33
35
  :persist,
34
- :clear
36
+ :clear,
37
+ :exist?,
38
+ :fetch
35
39
  end
36
40
  end
@@ -11,7 +11,7 @@ module AnyCache::Adapters
11
11
  # @api private
12
12
  # @since 0.1.0
13
13
  def supported_driver?(driver)
14
- defined?(::Redis) && driver.is_a?(::Redis)
14
+ AnyCache::Drivers::Redis.supported_source?(driver)
15
15
  end
16
16
  end
17
17
 
@@ -42,7 +42,8 @@ module AnyCache::Adapters
42
42
  :incrby,
43
43
  :decrby,
44
44
  :pipelined,
45
- :flushdb
45
+ :flushdb,
46
+ :exists
46
47
 
47
48
  # @param key [String]
48
49
  # @param options [Hash]
@@ -88,7 +89,6 @@ module AnyCache::Adapters
88
89
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
89
90
  new_amount = nil
90
91
 
91
- # TODO: think about Redis#multi
92
92
  pipelined do
93
93
  new_amount = incrby(key, amount)
94
94
  expire(key, expires_in: expires_in) if expires_in
@@ -108,7 +108,6 @@ module AnyCache::Adapters
108
108
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
109
109
  new_amount = nil
110
110
 
111
- # TODO: think about Redis#multi
112
111
  pipelined do
113
112
  new_amount = decrby(key, amount)
114
113
  expire(key, expires_in: expires_in) if expires_in
@@ -147,5 +146,32 @@ module AnyCache::Adapters
147
146
  def clear(**options)
148
147
  flushdb
149
148
  end
149
+
150
+ # @param key [String]
151
+ # @param options [Hash]
152
+ # @return [Boolean]
153
+ #
154
+ # @api private
155
+ # @since 0.2.0
156
+ def exist?(key, **options)
157
+ exists(key)
158
+ 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
150
176
  end
151
177
  end
@@ -11,7 +11,7 @@ module AnyCache::Adapters
11
11
  # @api private
12
12
  # @since 0.1.0
13
13
  def supported_driver?(driver)
14
- defined?(::Redis::Store) && driver.is_a?(::Redis::Store)
14
+ AnyCache::Drivers::RedisStore.supported_source?(driver)
15
15
  end
16
16
  end
17
17
 
@@ -22,7 +22,9 @@ module AnyCache::Adapters
22
22
  # @api private
23
23
  # @since 0.1.0
24
24
  def read(key, **options)
25
- get(key, raw: true)
25
+ raw = options.fetch(:raw, true)
26
+
27
+ get(key, raw: raw)
26
28
  end
27
29
 
28
30
  # @param key [String]
@@ -34,8 +36,9 @@ module AnyCache::Adapters
34
36
  # @since 0.1.0
35
37
  def write(key, value, **options)
36
38
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
39
+ raw = options.fetch(:raw, true)
37
40
 
38
- expires_in ? setex(key, expires_in, value, raw: true) : set(key, value, raw: true)
41
+ expires_in ? setex(key, expires_in, value, raw: raw) : set(key, value, raw: raw)
39
42
  end
40
43
  end
41
44
  end
@@ -12,12 +12,13 @@ module AnyCache::Adapters
12
12
  require_relative 'adapters/active_support_file_store'
13
13
  require_relative 'adapters/active_support_redis_cache_store'
14
14
  require_relative 'adapters/active_support_memory_store'
15
+ require_relative 'adapters/active_support_mem_cache_store'
15
16
 
16
17
  class << self
17
18
  # @param driver [Object]
18
19
  # @return [AnyCache::Adapters::Basic]
19
20
  #
20
- # @raise [AnyCache::UnsupportedCacheDriverError]
21
+ # @raise [AnyCache::UnsupportedDriverError]
21
22
  #
22
23
  # @api private
23
24
  # @since 0.1.0
@@ -30,9 +31,10 @@ module AnyCache::Adapters
30
31
  when ActiveSupportRedisCacheStore.supported_driver?(driver) then ActiveSupportRedisCacheStore.new(driver)
31
32
  when ActiveSupportMemoryStore.supported_driver?(driver) then ActiveSupportMemoryStore.new(driver)
32
33
  when ActiveSupportFileStore.supported_driver?(driver) then ActiveSupportFileStore.new(driver)
34
+ when ActiveSupportMemCacheStore.supported_driver?(driver) then ActiveSupportMemCacheStore.new(driver)
33
35
  when Delegator.supported_driver?(driver) then Delegator.new(driver)
34
36
  else
35
- raise AnyCache::UnsupportedCacheDriverError
37
+ raise AnyCache::UnsupportedDriverError
36
38
  end
37
39
  end
38
40
  # rubocop:enable Metrics/LineLength
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.2.0
5
+ module AnyCache::Drivers::ActiveSupportFileStore
6
+ class << self
7
+ # @param driver [::ActiveSupport::Cache::FileStore]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.2.0
12
+ def supported_source?(driver)
13
+ defined?(::ActiveSupport::Cache::FileStore) &&
14
+ driver.is_a?(::ActiveSupport::Cache::FileStore)
15
+ end
16
+
17
+ # @param settings [Qonfig::Settings]
18
+ # @return [::ActiveSupport::Cache::FileStore]
19
+ #
20
+ # @api private
21
+ # @sicne 0.2.0
22
+ def build(settings)
23
+ ::ActiveSupport::Cache::FileStore.new(settings.cache_path, settings.options)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnyCache::Drivers::ActiveSupportMemCacheStore
4
+ class << self
5
+ # @param driver [::ActiveSupport::Cache::MemCacheStore]
6
+ # @return [Boolean]
7
+ #
8
+ # @api private
9
+ # @since 0.2.0
10
+ def supported_source?(driver)
11
+ defined?(::Dalli) &&
12
+ defined?(::ActiveSupport::Cache::MemCacheStore) &&
13
+ driver.is_a?(::ActiveSupport::Cache::MemCacheStore)
14
+ end
15
+
16
+ # @param settings [Qonfig:Settings]
17
+ # @return [::ActiveSupport::Cache::MemCacheStore]
18
+ #
19
+ # @api private
20
+ # @since 0.2.0
21
+ def build(settings)
22
+ ::ActiveSupport::Cache::MemCacheStore.new([Array(settings.servers), settings.options])
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.2.0
5
+ module AnyCache::Drivers::ActiveSupportMemoryStore
6
+ class << self
7
+ # @param driver [::ActiveSupport::Cache::MemoryStore]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.2.0
12
+ def supported_source?(driver)
13
+ defined?(::ActiveSupport::Cache::MemoryStore) &&
14
+ driver.is_a?(::ActiveSupport::Cache::MemoryStore)
15
+ end
16
+
17
+ # @param settings [Qonfig::Settings]
18
+ # @return [::ActiveSupport::Cache::MemoryStore]
19
+ #
20
+ # @api private
21
+ # @sicne 0.2.0
22
+ def build(settings)
23
+ ::ActiveSupport::Cache::MemoryStore.new(settings.options)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.2.0
5
+ module AnyCache::Drivers::ActiveSupportRedisCacheStore
6
+ class << self
7
+ # @param driver [::ActiveSupport::Cache::RedisCacheStore]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.2.0
12
+ def supported_source?(driver)
13
+ defined?(::Redis) &&
14
+ defined?(::ActiveSupport::Cache::RedisCacheStore) &&
15
+ driver.is_a?(::ActiveSupport::Cache::RedisCacheStore)
16
+ end
17
+
18
+ # @param settings [Qonfig::Settings]
19
+ # @return [::ActiveSupport::Cache::RedisCacheStore]
20
+ #
21
+ # @api private
22
+ # @sicne 0.2.0
23
+ def build(settings)
24
+ ::ActiveSupport::Cache::RedisCacheStore.new(settings.options)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.2.0
5
+ module AnyCache::Drivers::Dalli
6
+ class << self
7
+ # @param driver [::Dalli::Client]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.2.0
12
+ def supported_source?(driver)
13
+ defined?(::Dalli::Client) && driver.is_a?(::Dalli::Client)
14
+ end
15
+
16
+ # @param settings [Qonfig::Settings]
17
+ # @return [::Dalli::Client]
18
+ #
19
+ # @api private
20
+ # @sicne 0.2.0
21
+ def build(settings)
22
+ ::Dalli::Client.new(Array(settings.servers), settings.options)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.2.0
5
+ module AnyCache::Drivers::Redis
6
+ class << self
7
+ # @param driver [::Redis]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.2.0
12
+ def supported_source?(driver)
13
+ defined?(::Redis) && driver.is_a?(::Redis)
14
+ end
15
+
16
+ # @param settings [Qonfig::Settings]
17
+ # @return [::Redis]
18
+ #
19
+ # @api private
20
+ # @sicne 0.2.0
21
+ def build(settings)
22
+ ::Redis.new(settings.options)
23
+ end
24
+ end
25
+ end