Class: LaunchDarkly::ThreadSafeMemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/cache_store.rb

Overview

A thread-safe in-memory store suitable for use with the Faraday caching HTTP client. Uses the Threadsafe gem as the underlying cache.

Instance Method Summary collapse

Constructor Details

#initializeThreadSafeMemoryStore

Default constructor



16
17
18
# File 'lib/ldclient-rb/cache_store.rb', line 16

def initialize
  @cache = ThreadSafe::Cache.new
end

Instance Method Details

#delete(key) ⇒ Object

Delete a value in the cache

Parameters:

  • key (Object)

    the cache key



42
43
44
# File 'lib/ldclient-rb/cache_store.rb', line 42

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

#read(key) ⇒ Object

Read a value from the cache

Parameters:

  • key (Object)

    the cache key

Returns:

  • (Object)

    the cache value



25
26
27
# File 'lib/ldclient-rb/cache_store.rb', line 25

def read(key)
  @cache[key]
end

#write(key, value) ⇒ Object

Store a value in the cache

Parameters:

  • key (Object)

    the cache key

  • value (Object)

    the value to associate with the key

Returns:

  • (Object)

    the value



35
36
37
# File 'lib/ldclient-rb/cache_store.rb', line 35

def write(key, value)
  @cache[key] = value
end