Web缓存代理服务器 [英] Web Caching proxy server
本文介绍了Web缓存代理服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在代理服务器中开发一个应用程序,该应用程序能够缓存网页,以后我会用它来缓存浏览更多次的网页.
所以我想要一个C#的代码.如果有人可以帮助我的话.
或执行此操作的首选步骤(算法)是什么?
最好的问候...
解决方案
这里是一个起点,此链接包含一些代理服务器代码.
http://code.cheesydesign.com/?p=393 [ 受保护的 静态 字符串 UrlToFilename(字符串 url){ // 对于jpegs和height字段,在?之后的位为?似乎因机器而异 字符串 filename = url; // 截断文件名,如果文件名太长则添加一个哈希值 如果(文件名.长度> 160 ){ MD5哈希= MD5.Create(); 字节 [] hexResult = hash.ComputeHash(Encoding.Unicode.GetBytes(url)); 文件名=文件名.Substring( 0 , 160 )+ BitConverter.ToString(hexResult).Replace(" ," ); } int 索引; while ((index = filename.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()))!= -1){ filename = filename.Replace(filename [index],' _'); } 返回文件名; }
然后,您可以从此处将文件存储在您选择的目录结构中,并在代理服务器中检查文件是否存在,如果有,请使用文件,否则从互联网上获取.
>
I want to develop an application in the proxy server, which is capable of caching the web pages, which i would use later to cache pages which i would have browsed more times.
So i want a code in C# for that. if anybody could help me for that.
OR what are the preferred steps (algorithms) to do that?
Best regards...
解决方案
Here''s a starting point, this link has some proxy server code.
http://code.cheesydesign.com/?p=393[^]
Then what you need is an algorithm to change the URL to a filename, which you can store in your cache. So some code like this:
protected static string UrlToFilename(string url) { // With jpegs and height fields the bits after the ? seem to vary from machine to machine string filename = url; // Truncate the filename and add a hash if it is too long if (filename.Length > 160) { MD5 hash = MD5.Create(); byte[] hexResult = hash.ComputeHash(Encoding.Unicode.GetBytes(url)); filename = filename.Substring(0, 160) + BitConverter.ToString(hexResult).Replace("-", ""); } int index; while ((index = filename.IndexOfAny(System.IO.Path.GetInvalidFileNameChars())) != -1) { filename = filename.Replace(filename[index], '_'); } return filename; }
Then from here you can store the files in a directory structure of your choosing, and in the proxy server, check if the file exists, if so use the file, else fetch from the internet.
这篇关于Web缓存代理服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文