2001-02-27 08:27:55 +03:00
|
|
|
function getCacheService()
|
|
|
|
{
|
|
|
|
var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"];
|
|
|
|
var service = nsCacheService.getService(Components.interfaces.nsICacheService);
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createCacheSession(clientID, storagePolicy, streamable)
|
|
|
|
{
|
|
|
|
var service = getCacheService();
|
|
|
|
var nsICache = Components.interfaces.nsICache;
|
|
|
|
var session = service.createSession(clientID, storagePolicy, streamable);
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
function openCacheEntry(clientID, url)
|
|
|
|
{
|
|
|
|
var nsICache = Components.interfaces.nsICache;
|
|
|
|
var session = createCacheSession(clientID, nsICache.STORE_ANYWHERE, false);
|
|
|
|
var entry = session.openCacheEntry(url, nsICache.ACCESS_READ_WRITE);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2001-03-01 03:24:33 +03:00
|
|
|
function wrapString(str)
|
|
|
|
{
|
2002-08-06 04:53:19 +04:00
|
|
|
var nsISupportsCString = Components.interfaces.nsISupportsCString;
|
|
|
|
var factory = Components.classes["@mozilla.org/supports-cstring;1"];
|
|
|
|
var wrapper = factory.createInstance(nsISupportsCString);
|
2001-03-01 03:24:33 +03:00
|
|
|
wrapper.data = str;
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
2001-03-12 18:36:51 +03:00
|
|
|
function test()
|
|
|
|
{
|
|
|
|
var data = wrapString("javascript");
|
|
|
|
var entry = openCacheEntry("javascript", "theme:button");
|
|
|
|
entry.cacheElement = data;
|
|
|
|
entry.markValid();
|
|
|
|
entry.close();
|
|
|
|
|
|
|
|
var newEntry = openCacheEntry("javascript", "theme:button");
|
|
|
|
if (newEntry.cacheElement === data)
|
|
|
|
print("object cache works.");
|
|
|
|
else
|
|
|
|
print("object cache failed.");
|
|
|
|
}
|
2001-02-27 08:27:55 +03:00
|
|
|
|
2001-03-12 18:36:51 +03:00
|
|
|
test();
|