Class: RdCache
- Inherits:
-
Object
- Object
- RdCache
- Defined in:
- lib/caches/rd_cache.rb
Class Method Summary collapse
-
.cache_exists? ⇒ Boolean
initialize.
- .client ⇒ Object
- .delete(key, options = {}) ⇒ Object
- .initialize ⇒ Object
-
.read(key, options = {}) ⇒ Object
Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html.
- .write(key, value, options = {}) ⇒ Object
Class Method Details
.cache_exists? ⇒ Boolean
initialize
20 21 22 23 24 25 26 27 |
# File 'lib/caches/rd_cache.rb', line 20 def cache_exists? Net::HTTP.get(URI("http://#{@@config['host']}")) rescue Errno::ECONNREFUSED => error puts "**** Error: #{error.}" @@client = nil rescue Net::HTTPBadResponse => error # do nothing end |
.client ⇒ Object
7 8 9 |
# File 'lib/caches/rd_cache.rb', line 7 def client @@client end |
.delete(key, options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/caches/rd_cache.rb', line 42 def delete(key, = {}) return unless client deleted = read(key) client.del(key) deleted end |
.initialize ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/caches/rd_cache.rb', line 11 def initialize @@config ||= ConfigService.load_config('redis.yml')[ConfigService.environment] @@client ||= Redis.new(url: "redis://#{@@config['host']}") cache_exists? rescue Exception => error puts("RdCache.initialize error: #{error.}") @@client = nil end |
.read(key, options = {}) ⇒ Object
Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
31 32 33 34 |
# File 'lib/caches/rd_cache.rb', line 31 def read(key, = {}) return unless client client.get(key) end |
.write(key, value, options = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/caches/rd_cache.rb', line 36 def write(key, value, = {}) return unless client client.set(key, value) client.expire(key, [:expires_in]) if [:expires_in] end |