我们有一个客户端应用程序,允许用户下载全长192Kb/s的MP3音频文件。由于文件作为企业存储在我们外部,因此我们需要能够:
1)将文件从外部位置复制到本地服务器缓存
2)将该文件复制到请求该文件的客户端
显然,对同一文件的更多请求将来自缓存,而不需要到外部。
现在,我们已经有了一个当前的系统来做这件事(使用Squid缓存),但问题是2只有在1完全完成后才会执行。这意味着,如果将一个10分钟长的192kb/s磁道从外部位置复制到缓存需要75秒,那么客户端的HTTP超时大约为60秒!这不符合我们的要求。
似乎我们需要的是一个缓存,它可以在客户端从外部位置获取数据时向外传输数据。我的问题是:
1)可以使用Squid Cache (这是传统的现有缓存,不是我的选择)来实现这一点吗?
2)如果不是,什么技术最适合这种情况(成本不是问题)?
如果有任何不清楚的地方,请告诉我!
发布于 2009-04-10 12:21:12
这是我写的一个asp.net处理程序,用来代理来自另一台服务器的一些东西。第二次写入文件并使用该文件并不是那么困难。刷新循环中的响应将使其在下载时交付:
namespace bla.com
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Proxy : IHttpHandler
{
private static Regex urlRegex=new Regex(@"http://some_regex_here_to_prevent_abuse_of_proxy.mp3",RegexOptions.Compiled);
public void ProcessRequest(HttpContext context)
{
var targetUrl = context.Request.QueryString["url"];
MatchCollection matches = urlRegex.Matches(targetUrl);
if (matches.Count != 1 || matches[0].Value != targetUrl)
{
context.Response.StatusCode = 403;
context.Response.ContentType = "text/plain";
context.Response.Write("Forbidden");
return;
}
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(targetUrl);
Stream responseStream;
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
responseStream = response.GetResponseStream();
context.Response.ContentType = response.ContentType;
byte[] buffer = new byte[4096];
int amt;
while ((amt = responseStream.Read(buffer, 0, 4096))>0)
{
context.Response.OutputStream.Write(buffer, 0, amt);
Debug.WriteLine(amt);
}
responseStream.Close();
response.Close();
}
context.Response.Flush();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}https://stackoverflow.com/questions/737362
复制相似问题