michael@0: var DEBUG = true; michael@0: michael@0: var clientID = "javascript"; michael@0: var nsICache = Components.interfaces.nsICache; michael@0: michael@0: function getCacheService() michael@0: { michael@0: var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; michael@0: var service = nsCacheService.getService(Components.interfaces.nsICacheService); michael@0: return service; michael@0: } michael@0: michael@0: function CacheVisitor() michael@0: { michael@0: } michael@0: michael@0: CacheVisitor.prototype = { michael@0: QueryInterface : function(iid) michael@0: { michael@0: if (iid.equals(Components.interfaces.nsICacheVisitor)) michael@0: return this; michael@0: throw Components.results.NS_NOINTERFACE; michael@0: }, michael@0: michael@0: visitDevice : function(deviceID, deviceInfo) michael@0: { michael@0: print("[visiting device (deviceID = " + deviceID + ", description = " + deviceInfo.description + ")]"); michael@0: return true; michael@0: }, michael@0: michael@0: visitEntry : function(deviceID, entryInfo) michael@0: { michael@0: print("[visiting entry (clientID = " + entryInfo.clientID + ", key = " + entryInfo.key + ")]"); michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: function test() michael@0: { michael@0: var cacheService = getCacheService(); michael@0: var visitor = new CacheVisitor(); michael@0: cacheService.visitEntries(visitor); michael@0: } michael@0: michael@0: // load the cache service before doing anything with Java... michael@0: getCacheService(); michael@0: michael@0: if (DEBUG) { michael@0: print("cache service loaded."); michael@0: } else { michael@0: print("running cache visitor test."); michael@0: test(); michael@0: print("cache visitor test complete."); michael@0: }