Class: RackJwtAegis::MemcachedAdapter
Overview
Instance Method Summary
collapse
build, #deserialize_value, #exist?, #serialize_value
Constructor Details
Returns a new instance of MemcachedAdapter.
183
184
185
186
187
188
189
190
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 183
def initialize(options = {})
super
require 'dalli' unless defined?(Dalli)
@memcached = Dalli::Client.new(options[:servers] || 'localhost:11211', options)
rescue LoadError
raise CacheError, "Dalli gem not found. Add 'gem \"dalli\"' to your Gemfile."
end
|
Instance Method Details
#clear ⇒ Object
214
215
216
217
218
219
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 214
def clear
@memcached.flush
true
rescue StandardError => e
raise CacheError, "Memcached clear error: #{e.message}"
end
|
#delete(key) ⇒ Object
207
208
209
210
211
212
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 207
def delete(key)
@memcached.delete(key.to_s)
true
rescue StandardError => e
raise CacheError, "Memcached delete error: #{e.message}"
end
|
#read(key) ⇒ Object
192
193
194
195
196
197
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 192
def read(key)
value = @memcached.get(key.to_s)
deserialize_value(value)
rescue StandardError => e
raise CacheError, "Memcached read error: #{e.message}"
end
|
#write(key, value, expires_in: nil) ⇒ Object
199
200
201
202
203
204
205
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 199
def write(key, value, expires_in: nil)
serialized_value = serialize_value(value)
@memcached.set(key.to_s, serialized_value, expires_in&.to_i)
true
rescue StandardError => e
raise CacheError, "Memcached write error: #{e.message}"
end
|