Class: SplitIoClient::LocalStore

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-cache/local_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



13
14
15
# File 'lib/splitclient-cache/local_store.rb', line 13

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

Instance Method Details

#delete(key) ⇒ Object

deletes value from cache by given key

Parameters:

  • key (Object)

    the cache key



39
40
41
# File 'lib/splitclient-cache/local_store.rb', line 39

def delete(key)
  @cache[key] = nil
end

#read(key) ⇒ Object

Read a value from the cache

Parameters:

  • key (Object)

    the cache key

Returns:

  • (Object)

    the cache value



22
23
24
# File 'lib/splitclient-cache/local_store.rb', line 22

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



32
33
34
# File 'lib/splitclient-cache/local_store.rb', line 32

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