Class: Cache::Backend::IronCache

Inherits:
Object
  • Object
show all
Defined in:
lib/cache-backend-iron-cache.rb,
lib/cache-backend-iron-cache/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Constructor Details

#initialize(project_id, token, cache, options = {}) ⇒ IronCache

Returns a new instance of IronCache.



9
10
11
12
# File 'lib/cache-backend-iron-cache.rb', line 9

def initialize(project_id, token, cache, options = {})
  options = {project_id: project_id, token: token}.merge(options)
  @client = ::IronCache::Client.new(options).cache(cache)
end

Instance Method Details

#get(key) ⇒ Object



14
15
16
17
18
# File 'lib/cache-backend-iron-cache.rb', line 14

def get(key)
  value = @client.get(key)
  return unless value
  JSON.parse(value.value)['value']
end

#set(key, value) ⇒ Object



20
21
22
23
# File 'lib/cache-backend-iron-cache.rb', line 20

def set(key, value)
  @client.put(key, JSON.dump({value: value}))
  value
end