From: Aredridel Date: 2003-07-18T01:33:45+09:00 Subject: Re: OO Design question for Net::HTTP caching extension As far as modifying Net::HTTP#get and others to use the cache transparently, I think it makes sense since they could be cached anyway -- there's nothing that says the protocol can't have a local cache, as long as it's HTTP/1.1. Anyway, though, I've decided to do otherwise for the moment simply because Net::HTTP connects a socket upon new or start being called, and there's no good place to hook the cache there and still have keepalive be implemented cleanly. > (If you want a really serious cache then you wouldn't implement it in Ruby > anyway; you'd run Squid on your box and proxy through it. Looking at the > Squid documentation may give you some ideas on cache management, how to > handle object expiry in the absence of HTTP/1.1 information and so on) I've a really serious cache, but no need for as fast as squid, since there's just one process accessing it. . . No need for a daemon and massive cache filesystem when a dbm file is plenty ;-) Anyway, I'm now re-working to be an object with Net::HTTP's interface, and running into design issues around Net::HTTP and Net::HTTP::Proxy, thus: Net::HTTP::Proxy creates proxy objects that call Net::HTTP equivalents to do the dirty work, but override methods. The problem I have is that I have a third class with the same API, but that may need to delegate to either the Proxy or the raw HTTP class, and that sould be selectable at runtime, but Proxy makes the assumption that it's the only wrapper around Net::HTTP, so instantiating the cache will likely be harder than just using Net::HTTP or Net::HTTP::Proxy, since now instead of two options: * Net::HTTP * Net::HTTP::Proxy delegating to Net::HTTP there are four variants: * Net::HTTP * Net::HTTP::Proxy delegating to Net::HTTP * Net::HTTP::Cache delegating to Net::HTTP * Net::HTTP::Cache delegating to Net::HTTP::Proxy delegating to Net::HTTP so the Cache has to provide a way to select that easily if it is to be Net::HTTP API compatible. Ari