Transport connection caches must go.

Robey Pointer robey at lag.net
Tue May 23 19:15:40 BST 2006


On 23 May 2006, at 7:51, John A Meinel wrote:

> The reason we have per-transport caches, is because we cache different
> things for each transport. And the key for the cache may be  
> different. I
> personally don't like that the ftp cache includes the password in its
> key, as I don't like to remember passwords.
>
> We could cache the Transport objects themselves (say based on the  
> netloc
> portion of the URL), and then have get_transport() do a clone() if  
> there
> is a matching netloc.
> And then we would add a transport.flush_cache() function, which  
> could be
> called by the test suite.

I like a variation of this idea.

We only really want to check for reuse against currently-open  
transports, right?  So what if we added a method to Transport to ask  
if it can clone itself for an url?  Like so:

new_transport = old_transport.try_clone(url)

If the URL is incompatible (you asked an sftp transport to clone an  
http url), it returns None.

So you just keep a set of currently-open transports (weakref?) and  
when you want to open a new one, you iterate through the old ones and  
give them a chance to clone if they can.  The default Transport  
implementation would always return None, but transports could add a  
handler as an optimization.

That way you don't need a cache, you just need to track open  
transports and give them a chance to reuse their connections at a  
class level.

robey





More information about the bazaar mailing list