Class: WebFetch::Storage::Memcached
- Inherits:
-
Object
- Object
- WebFetch::Storage::Memcached
- Defined in:
- lib/web_fetch/storage/memcached.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(client = nil) ⇒ Memcached
constructor
A new instance of Memcached.
- #store(key, obj) ⇒ Object
Constructor Details
#initialize(client = nil) ⇒ Memcached
Returns a new instance of Memcached.
6 7 8 9 10 11 12 13 |
# File 'lib/web_fetch/storage/memcached.rb', line 6 def initialize(client = nil) require 'dalli' if client.nil? @client = client || Dalli::Client @config = { host: ENV.fetch('WEB_FETCH_MEMCACHED_HOST', 'localhost'), port: ENV.fetch('WEB_FETCH_MEMCACHED_PORT', '11211') } end |
Instance Method Details
#delete(key) ⇒ Object
26 27 28 |
# File 'lib/web_fetch/storage/memcached.rb', line 26 def delete(key) storage.delete(key) end |
#fetch(key) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/web_fetch/storage/memcached.rb', line 19 def fetch(key) result = storage.get(key) return JSON.parse(result, symbolize_names: true) unless result.nil? nil end |
#store(key, obj) ⇒ Object
15 16 17 |
# File 'lib/web_fetch/storage/memcached.rb', line 15 def store(key, obj) storage.set(key, obj.to_json) end |