Class: RackJwtAegis::SolidCacheAdapter

Inherits:
CacheAdapter show all
Defined in:
lib/rack_jwt_aegis/cache_adapter.rb

Overview

Solid Cache adapter (Rails 8+)

Since:

  • 0.1.0

Instance Method Summary collapse

Methods inherited from CacheAdapter

build, #deserialize_value, #exist?, #serialize_value

Constructor Details

#initialize(options = {}) ⇒ SolidCacheAdapter

Returns a new instance of SolidCacheAdapter.

Since:

  • 0.1.0



224
225
226
227
228
229
230
231
232
233
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 224

def initialize(options = {})
  super

  # Solid Cache should be available in Rails environment
  unless defined?(SolidCache)
    raise CacheError, "SolidCache not available. Ensure you're using Rails 8+ with Solid Cache configured."
  end

  @cache = options[:cache_instance] || SolidCache
end

Instance Method Details

#clearObject

Since:

  • 0.1.0



257
258
259
260
261
262
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 257

def clear
  @cache.clear
  true
rescue StandardError => e
  raise CacheError, "SolidCache clear error: #{e.message}"
end

#delete(key) ⇒ Object

Since:

  • 0.1.0



250
251
252
253
254
255
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 250

def delete(key)
  @cache.delete(key.to_s)
  true
rescue StandardError => e
  raise CacheError, "SolidCache delete error: #{e.message}"
end

#read(key) ⇒ Object

Since:

  • 0.1.0



235
236
237
238
239
240
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 235

def read(key)
  value = @cache.read(key.to_s)
  deserialize_value(value)
rescue StandardError => e
  raise CacheError, "SolidCache read error: #{e.message}"
end

#write(key, value, expires_in: nil) ⇒ Object

Since:

  • 0.1.0



242
243
244
245
246
247
248
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 242

def write(key, value, expires_in: nil)
  serialized_value = serialize_value(value)
  @cache.write(key.to_s, serialized_value, expires_in: expires_in)
  true
rescue StandardError => e
  raise CacheError, "SolidCache write error: #{e.message}"
end