Class: Bunq::ThreadSafeSessionCache

Inherits:
Object
  • Object
show all
Defined in:
lib/bunq/client.rb

Overview

A thread-safe session cache that can hold one (the current) session.

Usage:

Bunq.configure do |config|

config.session_cache = Bunq::ThreadSafeSessionCache.new

end

After this, all Bunq.client calls will use the same session. When the session times out, a new one is started automatically.

Constant Summary collapse

CACHE_KEY =
'CURRENT_BUNQ_SESSION'

Instance Method Summary collapse

Constructor Details

#initializeThreadSafeSessionCache

Returns a new instance of ThreadSafeSessionCache.



94
95
96
# File 'lib/bunq/client.rb', line 94

def initialize
  clear
end

Instance Method Details

#clearObject



102
103
104
# File 'lib/bunq/client.rb', line 102

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

#get(&block) ⇒ Object



98
99
100
# File 'lib/bunq/client.rb', line 98

def get(&block)
  @cache.fetch_or_store(CACHE_KEY) { block.call if block_given? }
end