cache_service 1.0.5 → 1.1.0
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 +8 -5
- data/lib/cache_service.rb +3 -3
- data/lib/caches/mc_cache.rb +2 -2
- data/lib/caches/rd_cache.rb +51 -0
- data/lib/services/cache_service.rb +0 -1
- metadata +46 -4
- data/lib/services/config_service.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9097d06614057304b120b95d5efa88c8a845c6
|
4
|
+
data.tar.gz: 30cb2b16f362987a33a2af75644302b483ec7e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec6951fd7b2d7e43ec3cb5f4d8f893d7ad1dd9588455f76df917655a514ccfddf57d3feb2865a1ca9b577a7063e95171591792e39d597e982ab3078242b7896d
|
7
|
+
data.tar.gz: 4084e118d7aa113b7ae5348c7d4ba491476d44ba274a3490e2f538d54b479c708754a65599bcb8be1e22fca5d2a7a2849ef2640cc58cfe27a0bdf7da12fcdf9c
|
data/cache_service.gemspec
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'cache_service'
|
3
|
-
s.version = '1.0
|
3
|
+
s.version = '1.1.0'
|
4
4
|
s.summary = "A gem for cache facility"
|
5
5
|
s.description = "A gem for cache facility"
|
6
6
|
s.authors = ['Linh Chau']
|
7
7
|
s.email = 'chauhonglinh@gmail.com'
|
8
8
|
s.files = [
|
9
9
|
'./cache_service.gemspec', 'lib/cache_service.rb',
|
10
|
-
'lib/services/
|
11
|
-
'lib/caches/mc_cache.rb', 'lib/caches/zk_cache.rb'
|
10
|
+
'lib/services/cache_service.rb', 'lib/services/sdk_logger.rb',
|
11
|
+
'lib/caches/mc_cache.rb', 'lib/caches/zk_cache.rb', 'lib/caches/rd_cache.rb'
|
12
12
|
]
|
13
13
|
s.homepage = 'https://github.com/linhchauatl/cache_service'
|
14
14
|
s.license = 'MIT'
|
15
15
|
s.add_runtime_dependency 'logging', '~> 0'
|
16
16
|
s.add_runtime_dependency 'activesupport'
|
17
|
-
s.add_runtime_dependency '
|
17
|
+
s.add_runtime_dependency 'config_service'
|
18
|
+
s.add_runtime_dependency 'redis'
|
19
|
+
s.add_runtime_dependency 'zookeeper'
|
20
|
+
s.add_runtime_dependency 'dalli', '~> 0'
|
18
21
|
|
19
22
|
s.add_development_dependency 'rspec', '~> 3.1'
|
20
|
-
end
|
23
|
+
end
|
data/lib/cache_service.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
2
|
+
require 'config_service'
|
3
3
|
|
4
4
|
def load_gem_lib(sub_path)
|
5
5
|
spec = Gem::Specification.find_by_name('cache_service')
|
@@ -12,5 +12,5 @@ end
|
|
12
12
|
['caches', 'services'].each do |sub_path|
|
13
13
|
load_gem_lib(sub_path)
|
14
14
|
rb_files = Dir.glob("#{File.expand_path('.')}/lib/#{sub_path}/*.rb")
|
15
|
-
rb_files.each { |rb_file| require rb_file }
|
16
|
-
end
|
15
|
+
rb_files.each { |rb_file| require rb_file }
|
16
|
+
end
|
data/lib/caches/mc_cache.rb
CHANGED
@@ -10,7 +10,7 @@ class McCache
|
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@@config ||= ConfigService.load_config('memcached.yml')[ConfigService.environment]
|
13
|
-
@@client ||= Dalli::Client.new(@@config['host'], @@config)
|
13
|
+
@@client ||= Dalli::Client.new(@@config['host'], { namespace: @@config.namespace, compress: @@config.compress})
|
14
14
|
cache_exists?
|
15
15
|
rescue Exception => error
|
16
16
|
puts("McCache.initialize error: #{error.message}")
|
@@ -50,4 +50,4 @@ class McCache
|
|
50
50
|
end #class methods
|
51
51
|
|
52
52
|
initialize
|
53
|
-
end
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
class RdCache
|
6
|
+
class << self
|
7
|
+
def client
|
8
|
+
@@client
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@@config ||= ConfigService.load_config('redis.yml')[ConfigService.environment]
|
13
|
+
@@client ||= Redis.new(url: "redis://#{@@config['host']}")
|
14
|
+
cache_exists?
|
15
|
+
rescue Exception => error
|
16
|
+
puts("RdCache.initialize error: #{error.message}")
|
17
|
+
@@client = nil
|
18
|
+
end #initialize
|
19
|
+
|
20
|
+
def cache_exists?
|
21
|
+
Net::HTTP.get(URI("http://#{@@config['host']}"))
|
22
|
+
rescue Errno::ECONNREFUSED => error
|
23
|
+
puts "**** Error: #{error.message}"
|
24
|
+
@@client = nil
|
25
|
+
rescue Net::HTTPBadResponse => error
|
26
|
+
# do nothing
|
27
|
+
end
|
28
|
+
|
29
|
+
# Cache API, mimics ActiveSupport::Cache::Store
|
30
|
+
# http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
|
31
|
+
def read(key, options = {})
|
32
|
+
return unless client
|
33
|
+
client.get(key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def write(key, value, options = {})
|
37
|
+
return unless client
|
38
|
+
client.set(key, value)
|
39
|
+
client.expire(key, options[:expires_in]) if options[:expires_in]
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(key, options = {})
|
43
|
+
return unless client
|
44
|
+
deleted = read(key)
|
45
|
+
client.del(key)
|
46
|
+
deleted
|
47
|
+
end
|
48
|
+
end #class methods
|
49
|
+
|
50
|
+
initialize
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linh Chau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: config_service
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: zookeeper
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: dalli
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,9 +117,9 @@ files:
|
|
75
117
|
- "./cache_service.gemspec"
|
76
118
|
- lib/cache_service.rb
|
77
119
|
- lib/caches/mc_cache.rb
|
120
|
+
- lib/caches/rd_cache.rb
|
78
121
|
- lib/caches/zk_cache.rb
|
79
122
|
- lib/services/cache_service.rb
|
80
|
-
- lib/services/config_service.rb
|
81
123
|
- lib/services/sdk_logger.rb
|
82
124
|
homepage: https://github.com/linhchauatl/cache_service
|
83
125
|
licenses:
|
@@ -99,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
141
|
version: '0'
|
100
142
|
requirements: []
|
101
143
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.6.8
|
103
145
|
signing_key:
|
104
146
|
specification_version: 4
|
105
147
|
summary: A gem for cache facility
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require 'active_support/core_ext'
|
3
|
-
|
4
|
-
class ConfigService
|
5
|
-
class << self
|
6
|
-
def load_config(config_file_name)
|
7
|
-
app_root = (defined? APP_ROOT)? APP_ROOT : File.expand_path('.')
|
8
|
-
|
9
|
-
config_file = nil
|
10
|
-
['conf', 'config'].each do |sub_path|
|
11
|
-
if File.exist?("#{app_root}/#{sub_path}/#{config_file_name}")
|
12
|
-
config_file = "#{app_root}/#{sub_path}/#{config_file_name}"
|
13
|
-
break
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
raise("NON-Fatal: #{config_file_name} file not found. Ignoring cache type.") unless config_file
|
18
|
-
|
19
|
-
YAML.load_file(config_file)
|
20
|
-
end
|
21
|
-
|
22
|
-
def environment
|
23
|
-
return Rails.env if defined? Rails
|
24
|
-
return ENV['RACK_ENV'] if ENV['RACK_ENV'].present?
|
25
|
-
'local'
|
26
|
-
rescue => error
|
27
|
-
'local'
|
28
|
-
end
|
29
|
-
end # class methods
|
30
|
-
end
|