class Fastbeans::Client
Constants
- CALL_CACHE_SIZE
Attributes
cache_class[RW]
call_cache[R]
connection_class[RW]
Public Class Methods
new(host='127.0.0.1', port=12345, cache=nil, pool_opts={})
click to toggle source
# File lib/fastbeans/client.rb, line 15 def initialize(host='127.0.0.1', port=12345, cache=nil, pool_opts={}) @host, @port = host, port @call_cache = cache || Rufus::Lru::SynchronizedHash.new(CALL_CACHE_SIZE) @pool_opts = {:size => 5, :timeout => 5}.update(pool_opts) @connection_class = Fastbeans::Connection end
Public Instance Methods
cached_call(*data)
click to toggle source
# File lib/fastbeans/client.rb, line 45 def cached_call(*data) @call_cache[data] ||= call(*data) end
call(*data)
click to toggle source
# File lib/fastbeans/client.rb, line 32 def call(*data) Fastbeans.benchmark("Calling: #{data.first.inspect}") do pool.with do |conn| if data.last.is_a?(Hash) and (data.last.keys.to_set & Fastbeans::Request::OPTION_KEYS).size > 0 opts = data.pop else opts = {} end conn.call(data, opts) end end end
clear_call_cache!()
click to toggle source
# File lib/fastbeans/client.rb, line 28 def clear_call_cache! @call_cache.clear end
pool()
click to toggle source
# File lib/fastbeans/client.rb, line 22 def pool @pool ||= ConnectionPool.new(@pool_opts) do @connection_class.new(@host, @port) end end