`
flyPig
  • 浏览: 139583 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Java上clear Squid缓存

    博客分类:
  • Java
 
阅读更多
实现原理:
        构造TCP请求,调用Squid自带的Purge.
前提条件:
        Squid需要配置支持purge

 private void purge(String ip, int port, String uri) throws IOException {
        
        Socket sk = null;
        OutputStream os = null;
        try {
            String msg = "PURGE " + uri + " HTTP/1.1\r\nAccept: */*\r\n\r\n";
            sk = new Socket(ip, port);
            os = sk.getOutputStream();
            os.write(msg.getBytes("UTF-8"));
            os.flush();
        } catch (UnknownHostException e) {
            logger.error("Resource purge error, " + ip + ":" + port + "is a unknown host!", e);
        } finally {
            if(os != null) {
                os.close();
            }
            if(sk != null) {
                sk.close();
            }
        }
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics