I am creating a Blackberry application to display a full screen web view of a certain site. I have a working browserfield that displays properly but navigation from page to page is slower than that of the native browser. The browserfield does not seem to have a built in cache causing the load time to be slow. When I add the following code to manage the cache the site no longer displays properly.

Any help that can be giving towards this will be greatly appreciated. This really has me stumped. Thanks.

UPDATE: It looks like the caching only works at a certain level of the Blackberry libraries. I have added logic to check the current Software level and turn on the caching if it is supported by the device's current software level. This provides me with a good work around, but i would still like to know if there is a better way for the caching to work with all devices.

UPDATE 2 Based on comments: The site no longer displaying properly pertains to site not displaying the proper layout, images and text. It basically give a white background with links and text displaying as a bulleted list, all formatting removed.

When you say "the site no longer displays properly" what do you mean? What happens when you use the cache?
–
TamarDec 29 '11 at 16:04

More detail would be helpful. no longer displays properlycaching only works at certain level... what does work mean? and what exactly happens when it doesn't work?
–
nlokoDec 31 '11 at 4:32

When you zsay you lose the cache content, you mean while navigating keeping visible the MainScreen, or when you close and reopen the screen? Do you create a new Browser Screen for every page you load?
–
Tomas NarrosJan 3 '12 at 9:01

Things like images and styles that are cached by the site are having to be reloaded for each page that comes up. When the caching is working, all pages after the home page load much quicker since these images are available in the cache.
–
Scott BoettgerJan 3 '12 at 12:36

@ScottBoettger, Can you check that the correct User-Agent is specified when you handling the HTTP requests? This could be a possible cause for the strange rendering.
–
GrahamJan 15 '12 at 22:05

1 Answer
1

I've been looking at your code, and the only thing I've found there's wrong with it, is you are completely ignoring the possibility of response.getLength(); returning less than zero (in CacheManagerImpl.createCache()). Although this didn't happen to me at the stackoverflow.com page, some pages use Transfer-Encoding: chunked, which means Content-Length is not present. This is, however, well handled, and should not cause the cache to fail (it would only be less effective).

I suggest testing your code on smaller problems, one step at a time. First, create cacheable page that only contains some text (like "hello") without any HTML tags. That should work pretty well, and in case it does not, it shouldn't be hard to determine where the data are getting lost. Or try to manually create cache item that does not expire and contains a webpage with no (external) stylesheet nor images, and see if it's even possible to pass it to BrowserField the way you do it. Then build on, add an image, add a style sheet so you can corner the problem.

The code is written very nicely, but at this point, it is not possible to help you because there are no evident flaws in the code and you are not explaining yourself very well, it is not clear how the error manifests itself, if it is every time or random, ... If I had a Blackberry device, I could probably try running the code for myself, but i don't.