Closed
Description
As outlined in #3, it may be useful to cache connections for SSHKit.Context
s so subsequent commands do not have to set up a new one each time.
Open questions/things to do:
- How do we cache connections?
- should be a KV-store erlang process
- probably store connections by
{hostname, port, username}
as the key? - commands always go to this process to fetch a connection
- if a connection with the same key doesn't exist yet, create, cache and return it
- else: return the cached connection unless it timed-out
- so it's more of a "connection provider" than just a "cache"
- How do we reuse the cached connections?
- do we pass them in to the
SSHKit.run
and.upload
functions? - do these methods access the (global) cache process?
- do we pass them in to the
Thoughts:
- use
GenServer
for the connection provider - could be set as part of the context, but have a default value so you do not need to explicitly pass it when just using the DSL
context = SSHKit.context(hosts, provider: SSHKit.ConnectionProvider.new)
# in SSHKit
def context(hosts, options \\ [provider: SSHit.ConnectionProvider.default])
…
end
def run(context, command) do
# fetch connections from the context's connection provider
# execute
end