artemk-cache-money 0.2.13.2 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/init.rb +1 -1
  2. data/rails/init.rb +46 -0
  3. metadata +4 -4
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'cache_money'
1
+ require File.join(File.basedir(__FILE__),'rails','init')
@@ -0,0 +1,46 @@
1
+ yml = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml")))
2
+ memcache_config = yml[RAILS_ENV]
3
+ memcache_config.symbolize_keys! if memcache_config.respond_to?(:symbolize_keys!)
4
+
5
+ if defined?(DISABLE_CACHE_MONEY) || ENV['DISABLE_CACHE_MONEY'] == 'true' || memcache_config.nil? || memcache_config[:cache_money] != true
6
+ Rails.logger.info 'cache-money disabled'
7
+ class ActiveRecord::Base
8
+ def self.index(*args)
9
+ end
10
+ end
11
+ else
12
+ Rails.logger.info 'cache-money enabled'
13
+ require 'cache_money'
14
+
15
+ memcache_config[:logger] = Rails.logger
16
+ memcache_servers =
17
+ case memcache_config[:servers].class.to_s
18
+ when "String"; memcache_config[:servers].gsub(' ', '').split(',')
19
+ when "Array"; memcache_config[:servers]
20
+ end
21
+ $memcache = MemcachedWrapper.new(memcache_servers, memcache_config)
22
+ puts $memcache.inspect
23
+
24
+ #ActionController::Base.cache_store = :cache_money_mem_cache_store
25
+ ActionController::Base.session_options[:cache] = $memcache if memcache_config[:sessions]
26
+ #silence_warnings {
27
+ # Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(:cache_money_mem_cache_store)
28
+ #}
29
+
30
+ $local = Cash::Local.new($memcache)
31
+ $lock = Cash::Lock.new($memcache)
32
+ $cache = Cash::Transactional.new($local, $lock)
33
+
34
+ # allow setting up caching on a per-model basis
35
+ if memcache_config[:automatic_caching].to_s == 'false'
36
+ Rails.logger.info "cache-money: global model caching disabled"
37
+ class ActiveRecord::Base
38
+ is_cached(false)
39
+ end
40
+ else
41
+ Rails.logger.info "cache-money: global model caching enabled"
42
+ class ActiveRecord::Base
43
+ is_cached(:repository => $cache)
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artemk-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 111
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 13
10
- - 2
11
- version: 0.2.13.2
9
+ - 14
10
+ version: 0.2.14
12
11
  platform: ruby
13
12
  authors:
14
13
  - Nick Kallen
@@ -93,6 +92,7 @@ files:
93
92
  - lib/mem_cached_session_store.rb
94
93
  - lib/mem_cached_support_store.rb
95
94
  - lib/memcached_wrapper.rb
95
+ - rails/init.rb
96
96
  - LICENSE
97
97
  - README.markdown
98
98
  - config/environment.rb