Class: McCache
- Inherits:
-
Object
- Object
- McCache
- Defined in:
- lib/caches/mc_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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/caches/mc_cache.rb', line 18 def cache_exists? # @@client.read('test') # rescue Exception => error # @@client = nil 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
5 6 7 |
# File 'lib/caches/mc_cache.rb', line 5 def client @@client end |
.delete(key, options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/caches/mc_cache.rb', line 42 def delete(key, = {}) return unless client deleted = read(key) client.delete(key) deleted end |
.initialize ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/caches/mc_cache.rb', line 9 def initialize @@config ||= ConfigService.load_config('memcached.yml')[ConfigService.environment] @@client ||= Dalli::Client.new(@@config['host'], @@config) cache_exists? rescue Exception => error puts("McCache.initialize error: #{error.}") @@client = nil end |
.read(key, options = {}) ⇒ Object
Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
32 33 34 35 |
# File 'lib/caches/mc_cache.rb', line 32 def read(key, = {}) return unless client client.get(key, ) end |
.write(key, value, options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/caches/mc_cache.rb', line 37 def write(key, value, = {}) return unless client client.set(key, value, [:expires_in], ) end |