Class: LaunchDarkly::ThreadSafeMemoryStore

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

Overview

A thread-safe in-memory store that uses the same semantics that Faraday would expect, although we no longer use Faraday. This is used by Requestor, when we are not in a Rails environment.

Instance Method Summary collapse

Constructor Details

#initializeThreadSafeMemoryStore

Default constructor



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

def initialize
  @cache = Concurrent::Map.new
end

Instance Method Details

#delete(key) ⇒ Object

Delete a value in the cache

Parameters:

  • key (Object)

    the cache key



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

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



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

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



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

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