Article    Discussion    Edit    History

Web Document Cache Mechanism

Jump to: navigation, search

Like any typical Web browser, Genesis includes a mechanism for cacheing Web documents. This mechanism can certainly be improved, but I have found the following useful enough for the current state of affairs.

Before getting into details, what you probably want is a way to get the contents of a Web page over HTTP. This is how you should do that:

import org.dftproject.genesis.core.http.HttpUtils;
 
class MyTest {
 
	public void testGetWebPage() {
		// Get the contents of a web page
		String contents = HttpUtils.getWebPage("http://www.dftproject.org");
 
		// Print those contents to the console
		System.out.println(contents);
	}
 
}

Appearances suggest that the getWebPage method will request a copy of the Web page from the server and return its contents, but appearances are in this case deceiving. Behind the scenes this method is using the Genesis cache, which will fetch a copy of the Web page if this is the first time, or use an old copy of the Web page if one exists. Also, if more than one thread is trying to access the same Web page at the same time, they will all wait until we get back a single copy of it and then share that copy. Nifty, eh?

Retrieved from "http://www.dftproject.org/wiki/Web_Document_Cache_Mechanism"