Hi Michael, Thanks for your suggestion! It looks like that was indeed the problem. My code was derived from Google's Hello World ResourceStore demo. In this demo, they declare "var store;" inside the capture function. I declared "var store;" at the global level and still get a reference to the store from localServer each time capture is called.
It looks like it's working as the system is on the 271st link and still going strong. Michael, do you work for Google? If not, perhaps someone with permissions to edit that demo could either fix the code or modify the docs to identify that this store variable needs to be declared globally. I don't think it's a bug for JavaScript to garbage collect local variables when a function is completed its execution, especially if the code is running asynchronously, which would allow the function to complete running yet still have a situation where the store is busy. Thanks again for the tip! James Mortensen On Wed, May 27, 2009 at 5:59 PM, Michael Nordman <[email protected]>wrote: > > > Are there any workarounds to ensure that the system continues to > cache... > > I think there is. I think your 'store' object is being garbage > collected prior to finishing. Have you tried declaring var store at > the global scope? > > Many people have bumped into this problem, Gears should probably be > changed to prevent a busy store from being GCd. > > > On Wed, May 27, 2009 at 4:18 PM, James M<[email protected]> wrote: > > > > Hello, > > > > I think this is a bug. I have about 1000 Urls that I need to cache > > for a web application. Since there are a thousand URLS, the > > possibility of invalid URLS makes using a ManagedResourceStore an > > unreliable solution. With a ManagedResourceStore, the URLs are cached > > one by one until a 404 error is encountered, then caching halts! > > > > The documentation states that all the URLs in the manifest file must > > be valid, which is unfortunate, because an invalid url at slot 252 > > means that 251 of the 1000 urls are cached successfully while the > > remainder are just tossed out by Google Gears! > > > > I have been exploring using a ResourceStore. I was looking at the > > sample application > http://code.google.com/apis/gears/samples/hello_world_resourcestore.html > > and noticed that If I removed one of the files to force a 404 error, > > the system continued to cache the remaining files! This is exactly > > what I needed! > > > > So I took my manifest file, loaded all of the files into an array, and > > used the ResourceStore explicit capture method to pass in an array of > > URLS. > > > > I get anywhere from 2 to 30 files cached and then the system -- > > without warning -- just stops caching! Even if all of the URLs are > > valid 200 responses it just suddenly stops! > > > > This to me seems like a bug in the ResourceStore class/object, and > > I've found no documentation suggesting that ResourceStores have a > > timeout. Any suggestions? Is this a bug that needs to be reported to > > the Gears Development team? Are there any workarounds to ensure that > > the system continues to cache valid urls even if one encountered is > > missing? > > > > Thanks, > > James Mortensen > > > > // I take the manifest file containing 998 urls and I use a for loop > > to load the contents into the filesToCapture array // from the sample > > app. > > function loadManifest() { > > var url = "large_manifest.json"; > > > > var req = new XMLHttpRequest(); > > req.onreadystatechange = function() { > > if(req.readyState == 4 && req.status == 200) { > > alert("loaded manifest file..."); > > > > // here I am stripping out the unneeded manifest metadata > > response = req.responseText.substring(16); > > eval("response = " + response); > > alert(response); > > alert(response.entries[0].url); > > alert(filesToCapture[0]); > > > > // here I am taking the entries.url properties and putting > > them in a normal array, just like in filesToCapture > > for(var i=0; i < response.entries.length; i++) { > > filesToCapture[i] = response.entries[i].url; > > } > > > > alert("length = " + filesToCapture.length); > > } > > }; > > > > req.open("GET",url,true); > > req.send(null); > > } > > > > // I tried passing in the entire array into the capture function, as > > well as using a for loop to call capture N > > //times where N is the number of files in the array. I only cached 1 > > or 2 files with the for loop, but about 10-30 > > // files by passing in the entire array as demonstrated in this > > function. > > function capture() { > > var store = localServer.openStore(STORE_NAME); > > if (!store) { > > setError('Please create a store for the captured resources'); > > return; > > } > > > > clearStatus(); > > addStatus('Capturing...'); > > > > count = 0; > > // Capture this page and the js library we need to run offline. > > > > // for(count=0; count<filesToCapture.length; count++) { > > store.capture(filesToCapture, captureCallback); > > // } > > } > > > > // this is the callback function that is called when each file is > > captured. I added the count variable to the status so > > // that I could enumerate each attempt. I get 15-30 files cached > > before the system just stops doing stuff with > > //no warnings or errors! > > function captureCallback(url, success, captureId) { > > addStatus(count + " " + url + ' captured ' + (success ? > > 'succeeded' : 'failed')); > > count++; > > } > > > > > -- James Mortensen Project Manager, VoiceCurve, Inc. 503-612-9765 ext 100526 [email protected]
