javascript PhantomJS 保持缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23390974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhantomJS keeping cache
提问by Charabon
I am using phantom js to test accessing a webpage, this runs approximatley 350 times in the space of about half an hour. I am then running webalizer against the server to test page accesses.
我正在使用 phantom js 来测试访问网页,这在大约半小时的时间内运行了大约 350 次。然后我在服务器上运行 webalizer 来测试页面访问。
My phantom js clients are inside 1 instance of phantom js so it basically works in the sense that once one client has opened the web page kick off the next client, all with individual IP addresses and MAC addresses throughout.
我的 phantom js 客户端位于 phantom js 的 1 个实例中,因此它的工作原理是,一旦一个客户端打开网页,就会启动下一个客户端,所有客户端都具有单独的 IP 地址和 MAC 地址。
However what I am finding in webalizer is that while I get 350 hits to the server I am only getting 1 hit per instance of phantomjs I run on some css files and others. So I have come up with the idea of it caching clients together.
但是,我在 webalizer 中发现的是,虽然我在服务器上获得了 350 次点击,但我在某些 css 文件和其他文件上运行的每个 phantomjs 实例仅获得 1 次点击。所以我想出了将客户端缓存在一起的想法。
I have attempted running --max-disk-cache-size=0 when calling the phantom js instance but still see it acting the same.
我尝试在调用 phantom js 实例时运行 --max-disk-cache-size=0 但仍然看到它的行为相同。
Has anyone experienced the same before?
有没有人经历过同样的事情?
回答by Fancyoung
Run page.clearMemoryCache();
before page.open
can clean cache.
运行page.clearMemoryCache();
之前page.open
可以清理缓存。
It metioned in this issue, and it works fine in PhantomJS 2.0.
它在这个 issue 中提到,它在 PhantomJS 2.0 中工作正常。
回答by Cybermaxs
There is no way to clear cache (memory or disk). An issue is open on github heresince a few months and I still hope this will be released in the future.
没有办法清除缓存(内存或磁盘)。几个月以来,这里的github 上有一个问题,我仍然希望将来能发布这个问题。
This only way is to start a new instance of phantomjs with no disk cache.
这唯一的方法是在没有磁盘缓存的情况下启动一个新的 phantomjs 实例。
PhantomJs is a headless browser, so please consider a PhantomJS instance as an unique user. Does opening 100 times the same web page in your favorite browser will downlaod 100 times every resources of your web page ? No, this is exactly how PhantomJS works.
PhantomJs 是无头浏览器,因此请将 PhantomJS 实例视为唯一用户。在您最喜欢的浏览器中打开 100 次相同的网页是否会下载您网页的每个资源 100 次?不,这正是 PhantomJS 的工作原理。