我们有一个客户端应用程序,允许用户下载全长192Kb / s的MP3音频文件。由于文件作为业务存储在我们外部,因此我们需要能够:
1)将文件从外部位置复制到本地服务器缓存
2)将该文件复制到请求它的客户端
显然,对同一文件的进一步请求将来自缓存,不需要外部。
现在,我们已经有了一个当前系统(使用Squid Cache),但问题是2只在1完全完成后才执行。这意味着如果一个10分钟长的192kb / s轨道需要75秒从外部位置复制到缓存中,客户端的HTTP超时将在大约60秒内启动!这不符合我们的要求。
我们需要的是一个可以转移到客户端的缓存,而不是从外部位置获取数据。我的问题是:
1)这可以通过Squid Cache完成(这是传统的老牌,而不是我的选择)?
2)如果没有,哪种技术最适合这种情况(成本不是真正的问题)?
如果不清楚,请告诉我!
答案 0 :(得分:1)
这是一个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;
}
}
}
}