cache_service 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cache_service.gemspec +1 -1
- data/lib/cache_service.rb +4 -10
- data/lib/caches/mc_cache.rb +20 -4
- data/lib/caches/zk_cache.rb +22 -4
- data/lib/services/cache_service.rb +5 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9e9ff2607b9833b46b489bb6ec8f47b8c9c5a8c
|
4
|
+
data.tar.gz: bc7a1ff3e9e9615d662c59b41a6ce3a25651cac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33a3fb5754b15b39f678384b08abe1e3329f150d1a99c30fc4f4ede33c45ba468c5eca3928cbba3050964c914f8a21abf966fa7840d83c5e4ca28f083042ae93
|
7
|
+
data.tar.gz: 8a1ea1c183f6501d50c4235883a68f68c06a0fa0859230f1a4f948a3419e93cba7be0198108a641037c76eba88ec3048e12e5c430b4c82da19015f43b595a1cc
|
data/cache_service.gemspec
CHANGED
data/lib/cache_service.rb
CHANGED
@@ -9,14 +9,8 @@ rescue Exception => error
|
|
9
9
|
# Who cares?
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
proc_dir('.').reject { |p| !p.ends_with?('.rb') }.each do |rb_file|
|
18
|
-
unless (rb_file == './lib/cache_service.rb' || rb_file.starts_with?('./spec/'))
|
19
|
-
require rb_file
|
20
|
-
puts "require #{rb_file}"
|
21
|
-
end
|
12
|
+
['caches', 'services'].each do |sub_path|
|
13
|
+
load_gem_lib(sub_path)
|
14
|
+
rb_files = Dir.glob("#{File.expand_path('.')}/lib/#{sub_path}/*.rb")
|
15
|
+
rb_files.each { |rb_file| require rb_file }
|
22
16
|
end
|
data/lib/caches/mc_cache.rb
CHANGED
@@ -7,24 +7,40 @@ class McCache
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
config
|
11
|
-
@@client ||= Dalli::Client.new(config['host'], config)
|
12
|
-
|
13
|
-
|
10
|
+
@@config ||= ConfigService.load_config('memcached.yml')[ConfigService.environment]
|
11
|
+
@@client ||= Dalli::Client.new(@@config['host'], @@config)
|
12
|
+
cache_exists?
|
13
|
+
rescue Exception => error
|
14
|
+
puts("McCache.initialize error: #{error.message}")
|
14
15
|
@@client = nil
|
15
16
|
end #initialize
|
16
17
|
|
18
|
+
def cache_exists?
|
19
|
+
# @@client.read('test')
|
20
|
+
# rescue Exception => error
|
21
|
+
# @@client = nil
|
22
|
+
Net::HTTP.get(URI("http://#{@@config['host']}"))
|
23
|
+
rescue Errno::ECONNREFUSED => error
|
24
|
+
puts "**** Error: #{error.message}"
|
25
|
+
@@client = nil
|
26
|
+
rescue Net::HTTPBadResponse => error
|
27
|
+
# do nothing
|
28
|
+
end
|
29
|
+
|
17
30
|
# Cache API, mimics ActiveSupport::Cache::Store
|
18
31
|
# http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
|
19
32
|
def read(key, options = {})
|
33
|
+
return unless client
|
20
34
|
client.get(key, options)
|
21
35
|
end
|
22
36
|
|
23
37
|
def write(key, value, options = {})
|
38
|
+
return unless client
|
24
39
|
client.set(key, value, options[:expires_in], options)
|
25
40
|
end
|
26
41
|
|
27
42
|
def delete(key, options = {})
|
43
|
+
return unless client
|
28
44
|
deleted = read(key)
|
29
45
|
client.delete(key)
|
30
46
|
deleted
|
data/lib/caches/zk_cache.rb
CHANGED
@@ -10,17 +10,31 @@ class ZkCache
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
config
|
14
|
-
@@client ||= Zookeeper.new(config['host'])
|
15
|
-
|
16
|
-
|
13
|
+
@@config ||= ConfigService.load_config('zookeeper.yml')[ConfigService.environment]
|
14
|
+
@@client ||= Zookeeper.new(@@config['host'])
|
15
|
+
cache_exists?
|
16
|
+
rescue Exception => error
|
17
|
+
puts("ZkCache.initialize error: #{error.message}")
|
17
18
|
@@client = nil
|
18
19
|
end #initialize
|
19
20
|
|
21
|
+
def cache_exists?
|
22
|
+
# @@client.read('test')
|
23
|
+
# rescue Exception => error
|
24
|
+
# @@client = nil
|
25
|
+
Net::HTTP.get(URI("http://#{@@config['host']}"))
|
26
|
+
rescue Errno::ECONNREFUSED => error
|
27
|
+
puts "**** Error: #{error.message}"
|
28
|
+
@@client = nil
|
29
|
+
rescue EOFError => error
|
30
|
+
# do nothing
|
31
|
+
end
|
20
32
|
|
21
33
|
# Cache API, mimics ActiveSupport::Cache::Store
|
22
34
|
# http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
|
23
35
|
def read(key, options = {})
|
36
|
+
return unless client
|
37
|
+
|
24
38
|
key = process_key(key)
|
25
39
|
result = client.get(path: key)[:data]
|
26
40
|
result = decode_data(result)
|
@@ -37,6 +51,8 @@ class ZkCache
|
|
37
51
|
end
|
38
52
|
|
39
53
|
def write(key, value, options = {})
|
54
|
+
return unless client
|
55
|
+
|
40
56
|
key = process_key(key)
|
41
57
|
init_key(key, nil)
|
42
58
|
written_value = value
|
@@ -53,6 +69,8 @@ class ZkCache
|
|
53
69
|
end
|
54
70
|
|
55
71
|
def delete(key, options = {})
|
72
|
+
return unless client
|
73
|
+
|
56
74
|
key = process_key(key)
|
57
75
|
deleted = read(key)
|
58
76
|
client.delete(path: key)
|
@@ -17,22 +17,23 @@ class CacheService
|
|
17
17
|
Dir.glob("#{File.expand_path('.')}/caches/*.rb").each { |rb_file| require rb_file }
|
18
18
|
@@cache ||= eval(config['cache'])
|
19
19
|
SdkLogger.logger = eval(config['logger']) if config['logger'].present?
|
20
|
-
rescue => error
|
20
|
+
rescue Exception => error
|
21
|
+
puts("Error #{error.message}")
|
21
22
|
@@cache = nil
|
22
23
|
end
|
23
24
|
|
24
25
|
def read(key, options = {})
|
25
|
-
return nil unless
|
26
|
+
return nil unless cache
|
26
27
|
cache.read(key, options)
|
27
28
|
end
|
28
29
|
|
29
30
|
def write(key, value, options = {})
|
30
|
-
return nil unless
|
31
|
+
return nil unless cache
|
31
32
|
cache.write(key, value, options)
|
32
33
|
end
|
33
34
|
|
34
35
|
def delete(key, options = {})
|
35
|
-
return nil unless
|
36
|
+
return nil unless cache
|
36
37
|
cache.delete(key, options)
|
37
38
|
end
|
38
39
|
end #class methods
|