HTMLUNIT Cache Implementation

本文详细介绍了如何使用Maven构建HTMLUNIT缓存实现,包括依赖管理、测试运行等关键步骤。通过MVN命令,实现项目的构建、测试与打包,深入理解缓存机制的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTMLUNIT Cache Implementation

I got the latest codes from this URL:
https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit

Use maven to manage the project, these commands
>mvn compile
>mvn clean compile

Build the dependency for IDE eclipse
>mvn eclipse:eclipse

Running the test with this command
>mvn test
>mvn test -Dtest=CacheTest

Packaging
>mvn -DskipTests=true package
>mvn -DskipTests=true source:jar
>mvn -DskipTests=true source:test-jar

Check the simple Cache implementation com.gargoylesoftware.htmlunit.Cache

The URL.toString will be the keys, and the contents will be the values. All these things are stored in HashMap.

Add some log message in class:
private static final Log LOG = LogFactory.getLog(Cache.class);

public Object getCachedObject(final WebRequest request) {
if (HttpMethod.GET != request.getHttpMethod()) {
return null;
}
final Entry cachedEntry = entries_.get(request.getUrl().toString());
if (cachedEntry == null) {
return null;
}
synchronized (entries_) {
cachedEntry.touch();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Cache is hit==========================size:" + this.getSize());
LOG.debug("key URL: " + request.getUrl().toString());
LOG.debug("Cache is hit==========================");
}
return cachedEntry.value_;
}

The test class is com.gargoylesoftware.htmlunit.CacheTest.

The class is as follow:
Cache htmlCache = new Cache();
webClient.setCache(htmlCache);

references:
http://htmlunit.sourceforge.net/gettingLatestCode.html
https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java
https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值