Class: OptimizelyServerSide::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/optimizely_server_side/cache.rb

Overview

Maintains the API config response in Memory store cache. user Activesupport MemoryStore store.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

We are sticking with Activesupprt memory store as gem is to be used with Rails app for now.



13
14
15
16
17
# File 'lib/optimizely_server_side/cache.rb', line 13

def initialize
  @cache_store_instance = ActiveSupport::Cache::MemoryStore.new(
    expires_in: OptimizelyServerSide.configuration.cache_expiry.send(:minutes)
  )
end

Instance Attribute Details

#cache_store_instanceObject (readonly)

Returns the value of attribute cache_store_instance.



9
10
11
# File 'lib/optimizely_server_side/cache.rb', line 9

def cache_store_instance
  @cache_store_instance
end

Class Method Details

.fetch(key) ⇒ Object

fetch is a wrapper on top of Activesupport Fetch to set/get the response via singleton instance



23
24
25
# File 'lib/optimizely_server_side/cache.rb', line 23

def fetch(key)
  instance.cache_store_instance.fetch(key) { yield }
end