makara 0.3.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/gem-publish-public.yml +36 -0
  3. data/.travis.yml +71 -9
  4. data/CHANGELOG.md +84 -25
  5. data/Gemfile +4 -3
  6. data/README.md +37 -34
  7. data/gemfiles/ar-head.gemfile +9 -0
  8. data/gemfiles/ar30.gemfile +7 -1
  9. data/gemfiles/ar31.gemfile +8 -1
  10. data/gemfiles/ar32.gemfile +8 -1
  11. data/gemfiles/ar40.gemfile +10 -1
  12. data/gemfiles/ar41.gemfile +10 -1
  13. data/gemfiles/ar42.gemfile +10 -1
  14. data/gemfiles/ar50.gemfile +11 -2
  15. data/gemfiles/ar51.gemfile +11 -2
  16. data/gemfiles/ar52.gemfile +24 -0
  17. data/gemfiles/ar60.gemfile +24 -0
  18. data/lib/active_record/connection_adapters/makara_abstract_adapter.rb +109 -3
  19. data/lib/active_record/connection_adapters/makara_postgis_adapter.rb +41 -0
  20. data/lib/makara.rb +15 -4
  21. data/lib/makara/cache.rb +4 -40
  22. data/lib/makara/config_parser.rb +14 -3
  23. data/lib/makara/connection_wrapper.rb +26 -2
  24. data/lib/makara/context.rb +108 -38
  25. data/lib/makara/cookie.rb +52 -0
  26. data/lib/makara/error_handler.rb +2 -2
  27. data/lib/makara/errors/blacklisted_while_in_transaction.rb +14 -0
  28. data/lib/makara/errors/invalid_shard.rb +16 -0
  29. data/lib/makara/logging/logger.rb +1 -1
  30. data/lib/makara/middleware.rb +12 -75
  31. data/lib/makara/pool.rb +53 -40
  32. data/lib/makara/proxy.rb +52 -30
  33. data/lib/makara/railtie.rb +0 -6
  34. data/lib/makara/strategies/round_robin.rb +6 -0
  35. data/lib/makara/strategies/shard_aware.rb +47 -0
  36. data/lib/makara/version.rb +2 -2
  37. data/makara.gemspec +5 -1
  38. data/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb +10 -5
  39. data/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb +17 -2
  40. data/spec/active_record/connection_adapters/makara_postgis_adapter_spec.rb +155 -0
  41. data/spec/active_record/connection_adapters/makara_postgresql_adapter_spec.rb +76 -3
  42. data/spec/cache_spec.rb +2 -52
  43. data/spec/config_parser_spec.rb +27 -13
  44. data/spec/connection_wrapper_spec.rb +5 -2
  45. data/spec/context_spec.rb +163 -100
  46. data/spec/cookie_spec.rb +72 -0
  47. data/spec/middleware_spec.rb +26 -55
  48. data/spec/pool_spec.rb +24 -0
  49. data/spec/proxy_spec.rb +51 -36
  50. data/spec/spec_helper.rb +5 -9
  51. data/spec/strategies/shard_aware_spec.rb +219 -0
  52. data/spec/support/helpers.rb +6 -2
  53. data/spec/support/mock_objects.rb +5 -1
  54. data/spec/support/mysql2_database.yml +1 -0
  55. data/spec/support/mysql2_database_with_custom_errors.yml +5 -0
  56. data/spec/support/postgis_database.yml +15 -0
  57. data/spec/support/postgis_schema.rb +11 -0
  58. data/spec/support/postgresql_database.yml +2 -0
  59. data/spec/support/proxy_extensions.rb +1 -1
  60. data/spec/support/schema.rb +5 -5
  61. data/spec/support/user.rb +5 -0
  62. metadata +28 -9
  63. data/lib/makara/cache/memory_store.rb +0 -28
  64. data/lib/makara/cache/noop_store.rb +0 -15
@@ -13,3 +13,12 @@ gem 'mysql2', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'pg', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -26,5 +26,11 @@ end
26
26
  if rmajor == 1 && (rminor == 8 || (rminor == 9 && rpatch < 3))
27
27
  gem 'pg', '0.17.1', :platform => :ruby
28
28
  else
29
- gem 'pg', :platform => :ruby
29
+ gem 'pg', '0.21.0', :platform => :ruby
30
+ end
31
+
32
+ # 2.1 +
33
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
34
+ gem 'activerecord-postgis-adapter', :platform => :ruby
35
+ gem 'rgeo', :platform => :ruby
30
36
  end
@@ -13,6 +13,7 @@ gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
15
15
 
16
+
16
17
  rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
17
18
 
18
19
  if rmajor == 1 && rminor == 8
@@ -25,5 +26,11 @@ end
25
26
  if rmajor == 1 && (rminor == 8 || (rminor == 9 && rpatch < 3))
26
27
  gem 'pg', '0.17.1', :platform => :ruby
27
28
  else
28
- gem 'pg', :platform => :ruby
29
+ gem 'pg', '0.21.0', :platform => :ruby
30
+ end
31
+
32
+ # 2.1 +
33
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
34
+ gem 'activerecord-postgis-adapter', :platform => :ruby
35
+ gem 'rgeo', :platform => :ruby
29
36
  end
@@ -13,6 +13,7 @@ gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
15
15
 
16
+
16
17
  rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
17
18
 
18
19
  if rmajor == 1 && rminor == 8
@@ -25,5 +26,11 @@ end
25
26
  if rmajor == 1 && (rminor == 8 || (rminor == 9 && rpatch < 3))
26
27
  gem 'pg', '0.17.1', :platform => :ruby
27
28
  else
28
- gem 'pg', :platform => :ruby
29
+ gem 'pg', '0.21.0', :platform => :ruby
30
+ end
31
+
32
+ # 2.1 +
33
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
34
+ gem 'activerecord-postgis-adapter', :platform => :ruby
35
+ gem 'rgeo', :platform => :ruby
29
36
  end
@@ -11,5 +11,14 @@ gem 'rack', '1.6.0'
11
11
  gem 'timecop'
12
12
  gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', :platform => :ruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -11,5 +11,14 @@ gem 'rack', '1.6.0'
11
11
  gem 'timecop'
12
12
  gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', :platform => :ruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -11,5 +11,14 @@ gem 'rack', '1.6.0'
11
11
  gem 'timecop'
12
12
  gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', :platform => :ruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -9,7 +9,16 @@ gem 'activerecord', '~> 5.0.0'
9
9
  gem 'rspec'
10
10
  gem 'rack'
11
11
  gem 'timecop'
12
- gem 'mysql2', :platform => :ruby
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', :platform => :ruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -9,7 +9,16 @@ gem 'activerecord', '~> 5.1.0'
9
9
  gem 'rspec'
10
10
  gem 'rack'
11
11
  gem 'timecop'
12
- gem 'mysql2', :platform => :ruby
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', :platform => :ruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in makara.gemspec
4
+ gemspec :path => '../'
5
+
6
+
7
+ gem 'rake'
8
+ gem 'activerecord', '~> 5.2.0'
9
+ gem 'rspec'
10
+ gem 'rack'
11
+ gem 'timecop'
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in makara.gemspec
4
+ gemspec :path => '../'
5
+
6
+
7
+ gem 'rake'
8
+ gem 'activerecord', '~> 6.0.0'
9
+ gem 'rspec'
10
+ gem 'rack'
11
+ gem 'timecop'
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'makara'
2
3
 
3
4
  module ActiveRecord
4
5
  module ConnectionAdapters
@@ -105,11 +106,15 @@ module ActiveRecord
105
106
  end
106
107
 
107
108
 
108
- hijack_method :execute, :select_rows, :exec_query, :transaction
109
+ hijack_method :execute, :exec_query, :exec_no_cache, :exec_cache, :transaction
109
110
  send_to_all :connect, :reconnect!, :verify!, :clear_cache!, :reset!
110
111
 
111
- SQL_MASTER_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i].map(&:freeze).freeze
112
- SQL_SLAVE_MATCHERS = [/\A\s*select\s/i].map(&:freeze).freeze
112
+ control_method :close, :steal!, :expire, :lease, :in_use?, :owner, :schema_cache, :pool=, :pool,
113
+ :schema_cache=, :lock, :seconds_idle, :==
114
+
115
+
116
+ SQL_MASTER_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i, /\A\s*select.+(nextval|currval|lastval|get_lock|release_lock|pg_advisory_lock|pg_advisory_unlock)\(/i].map(&:freeze).freeze
117
+ SQL_SLAVE_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].map(&:freeze).freeze
113
118
  SQL_ALL_MATCHERS = [/\A\s*set\s/i].map(&:freeze).freeze
114
119
  SQL_SKIP_STICKINESS_MATCHERS = [/\A\s*show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /\A\s*(set|describe|explain|pragma)\s/i].map(&:freeze).freeze
115
120
 
@@ -136,6 +141,7 @@ module ActiveRecord
136
141
 
137
142
  def initialize(config)
138
143
  @error_handler = ::ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ErrorHandler.new
144
+ @control = ActiveRecordPoolControl.new(self)
139
145
  super(config)
140
146
  end
141
147
 
@@ -205,7 +211,107 @@ module ActiveRecord
205
211
  raise NotImplementedError
206
212
  end
207
213
 
214
+ class ActiveRecordPoolControl
215
+ attr_reader :owner
216
+ alias :in_use? :owner
217
+
218
+ def initialize(proxy)
219
+ @proxy = proxy
220
+ @owner = nil
221
+ @pool = nil
222
+ @schema_cache = ActiveRecord::ConnectionAdapters::SchemaCache.new @proxy
223
+ @idle_since = Concurrent.monotonic_time
224
+ @adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(@proxy)
225
+ end
226
+
227
+ def close(*args)
228
+ @pool.checkin @proxy
229
+ end
230
+
231
+ # this method must only be called while holding connection pool's mutex
232
+ def lease(*args)
233
+ if in_use?
234
+ msg = +"Cannot lease connection, "
235
+ if @owner == Thread.current
236
+ msg << "it is already leased by the current thread."
237
+ else
238
+ msg << "it is already in use by a different thread: #{@owner}. " \
239
+ "Current thread: #{Thread.current}."
240
+ end
241
+ raise ActiveRecordError, msg
242
+ end
243
+ @owner = Thread.current
244
+ end
245
+
246
+ # this method must only be called while holding connection pool's mutex
247
+ def expire(*args)
248
+ if in_use?
249
+ if @owner != Thread.current
250
+ raise ActiveRecordError, "Cannot expire connection, " \
251
+ "it is owned by a different thread: #{@owner}. " \
252
+ "Current thread: #{Thread.current}."
253
+ end
254
+
255
+ @idle_since = Concurrent.monotonic_time
256
+ @owner = nil
257
+ else
258
+ raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
259
+ end
260
+ end
261
+
262
+ # Seconds since this connection was returned to the pool
263
+ def seconds_idle(*args)
264
+ return 0 if in_use?
265
+
266
+ Concurrent.monotonic_time - @idle_since
267
+ end
268
+
269
+ # this method must only be called while holding connection pool's mutex (and a desire for segfaults)
270
+ def steal!(*args)
271
+ if in_use?
272
+ if @owner != Thread.current
273
+ @pool.send :remove_connection_from_thread_cache, @proxy, @owner
274
+ @owner = Thread.current
275
+ end
276
+ else
277
+ raise ActiveRecordError, "Cannot steal connection, it is not currently leased."
278
+ end
279
+ end
280
+
281
+ def schema_cache(*args)
282
+ if @pool.respond_to?(:get_schema_cache) # AR6
283
+ @pool.get_schema_cache(@proxy)
284
+ else
285
+ @schema_cache
286
+ end
287
+ end
288
+
289
+ def schema_cache=(*args)
290
+ cache = args[0]
291
+ cache.connection = @proxy
292
+ if @pool.respond_to?(:set_schema_cache) # AR6
293
+ @pool.set_schema_cache(cache)
294
+ else
295
+ @schema_cache = cache
296
+ end
297
+ end
298
+
299
+ def lock(*args)
300
+ @adapter.lock
301
+ end
302
+
303
+ def pool=(*args)
304
+ @pool = args[0]
305
+ end
306
+
307
+ def pool(*args)
308
+ @pool
309
+ end
208
310
 
311
+ def ==(*args)
312
+ @proxy.object_id == args[0].object_id
313
+ end
314
+ end
209
315
  end
210
316
  end
211
317
  end
@@ -0,0 +1,41 @@
1
+ require 'active_record/connection_adapters/makara_abstract_adapter'
2
+ require 'active_record/connection_adapters/postgis_adapter'
3
+
4
+ if ActiveRecord::VERSION::MAJOR >= 4
5
+
6
+ module ActiveRecord
7
+ module ConnectionHandling
8
+ def makara_postgis_connection(config)
9
+ ActiveRecord::ConnectionAdapters::MakaraPostgisAdapter.new(config)
10
+ end
11
+ end
12
+ end
13
+
14
+ else
15
+
16
+ module ActiveRecord
17
+ class Base
18
+ def self.makara_postgis_connection(config)
19
+ ActiveRecord::ConnectionAdapters::MakaraPostgisAdapter.new(config)
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+
27
+ module ActiveRecord
28
+ module ConnectionAdapters
29
+ class MakaraPostgisAdapter < ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter
30
+ def self.visitor_for(*args)
31
+ ActiveRecord::ConnectionAdapters::PostGISAdapter.visitor_for(*args)
32
+ end
33
+
34
+ protected
35
+
36
+ def active_record_connection_for(config)
37
+ ::ActiveRecord::Base.postgis_connection(config)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'makara/version'
2
3
  require 'makara/railtie' if defined?(Rails)
3
4
  module Makara
@@ -6,16 +7,19 @@ module Makara
6
7
  autoload :ConfigParser, 'makara/config_parser'
7
8
  autoload :ConnectionWrapper, 'makara/connection_wrapper'
8
9
  autoload :Context, 'makara/context'
10
+ autoload :Cookie, 'makara/cookie'
9
11
  autoload :ErrorHandler, 'makara/error_handler'
10
12
  autoload :Middleware, 'makara/middleware'
11
13
  autoload :Pool, 'makara/pool'
12
14
  autoload :Proxy, 'makara/proxy'
13
15
 
14
16
  module Errors
15
- autoload :MakaraError, 'makara/errors/makara_error'
16
- autoload :AllConnectionsBlacklisted, 'makara/errors/all_connections_blacklisted'
17
- autoload :BlacklistConnection, 'makara/errors/blacklist_connection'
18
- autoload :NoConnectionsAvailable, 'makara/errors/no_connections_available'
17
+ autoload :MakaraError, 'makara/errors/makara_error'
18
+ autoload :AllConnectionsBlacklisted, 'makara/errors/all_connections_blacklisted'
19
+ autoload :BlacklistConnection, 'makara/errors/blacklist_connection'
20
+ autoload :NoConnectionsAvailable, 'makara/errors/no_connections_available'
21
+ autoload :BlacklistedWhileInTransaction, 'makara/errors/blacklisted_while_in_transaction'
22
+ autoload :InvalidShard, 'makara/errors/invalid_shard'
19
23
  end
20
24
 
21
25
  module Logging
@@ -27,6 +31,13 @@ module Makara
27
31
  autoload :Abstract, 'makara/strategies/abstract'
28
32
  autoload :RoundRobin, 'makara/strategies/round_robin'
29
33
  autoload :PriorityFailover, 'makara/strategies/priority_failover'
34
+ autoload :ShardAware, 'makara/strategies/shard_aware'
30
35
  end
31
36
 
32
37
  end
38
+
39
+ ActiveSupport.on_load(:active_record) do
40
+ ActiveRecord::LogSubscriber.log_subscribers.each do |subscriber|
41
+ subscriber.extend ::Makara::Logging::Subscriber
42
+ end
43
+ end
@@ -1,53 +1,17 @@
1
- require 'active_support/core_ext/object/try'
2
-
3
- # The Makara Cache should have access to your centralized cache store.
4
- # It serves the purpose of storing the Makara::Context across requests, servers, etc.
5
-
6
1
  module Makara
7
2
  module Cache
8
3
 
9
- autoload :MemoryStore, 'makara/cache/memory_store'
10
- autoload :NoopStore, 'makara/cache/noop_store'
11
-
12
4
  class << self
13
5
 
14
6
  def store=(store)
15
- @store = store
7
+ Makara::Logging::Logger.log deprecation_warning, :warn
16
8
  end
17
9
 
18
- def read(key)
19
- store.try(:read, key)
20
- end
10
+ private
21
11
 
22
- def write(key, value, ttl)
23
- store.try(:write, key, value, :expires_in => ttl.to_i)
12
+ def deprecation_warning
13
+ "Makara's context is no longer persisted in a backend cache, a cookie store is used by default.\nSetting the Makara::Cache.store won't have any effects."
24
14
  end
25
-
26
- protected
27
-
28
- def store
29
- case @store
30
- when :noop, :null
31
- @store = Makara::Cache::NoopStore.new
32
- when :memory
33
- @store = Makara::Cache::MemoryStore.new
34
- else
35
- if defined?(Rails)
36
-
37
- # in AR3 RAILS_CACHE may not be loaded if the full env is not present
38
- # Rails.cache will throw an error because of it.
39
- if ActiveRecord::VERSION::MAJOR < 4
40
- @store ||= Rails.cache if defined?(RAILS_CACHE)
41
- else
42
- @store ||= Rails.cache if defined?(Rails)
43
- end
44
- end
45
- end
46
-
47
- @store
48
- end
49
-
50
15
  end
51
-
52
16
  end
53
17
  end