Class: CodeToQuery::Performance::Cache::RailsCacheAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/code_to_query/performance/cache.rb

Overview

Adapter for Rails cache

Instance Method Summary collapse

Constructor Details

#initialize(rails_cache) ⇒ RailsCacheAdapter

Returns a new instance of RailsCacheAdapter.



164
165
166
# File 'lib/code_to_query/performance/cache.rb', line 164

def initialize(rails_cache)
  @rails_cache = rails_cache
end

Instance Method Details

#[](key) ⇒ Object



168
169
170
# File 'lib/code_to_query/performance/cache.rb', line 168

def [](key)
  @rails_cache.read(key)
end

#[]=(key, value) ⇒ Object



172
173
174
# File 'lib/code_to_query/performance/cache.rb', line 172

def []=(key, value)
  @rails_cache.write(key, value, expires_in: 3600) # 1 hour
end

#clearObject



180
181
182
# File 'lib/code_to_query/performance/cache.rb', line 180

def clear
  @rails_cache.clear
end

#delete(key) ⇒ Object



176
177
178
# File 'lib/code_to_query/performance/cache.rb', line 176

def delete(key)
  @rails_cache.delete(key)
end

#each(&block) ⇒ Object



189
190
191
192
# File 'lib/code_to_query/performance/cache.rb', line 189

def each(&block)
  # Rails cache doesn't support iteration
  # This limits our LRU eviction capability with Rails cache
end

#sizeObject



184
185
186
187
# File 'lib/code_to_query/performance/cache.rb', line 184

def size
  # Rails cache doesn't expose size easily
  0
end