|
1 function getCacheService() |
|
2 { |
|
3 var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; |
|
4 var service = nsCacheService.getService(Components.interfaces.nsICacheService); |
|
5 return service; |
|
6 } |
|
7 |
|
8 function createCacheSession(clientID, storagePolicy, streamable) |
|
9 { |
|
10 var service = getCacheService(); |
|
11 var nsICache = Components.interfaces.nsICache; |
|
12 var session = service.createSession(clientID, storagePolicy, streamable); |
|
13 return session; |
|
14 } |
|
15 |
|
16 function openCacheEntry(clientID, url) |
|
17 { |
|
18 var nsICache = Components.interfaces.nsICache; |
|
19 var session = createCacheSession(clientID, nsICache.STORE_ANYWHERE, false); |
|
20 var entry = session.openCacheEntry(url, nsICache.ACCESS_READ_WRITE); |
|
21 return entry; |
|
22 } |
|
23 |
|
24 function wrapString(str) |
|
25 { |
|
26 var nsISupportsCString = Components.interfaces.nsISupportsCString; |
|
27 var factory = Components.classes["@mozilla.org/supports-cstring;1"]; |
|
28 var wrapper = factory.createInstance(nsISupportsCString); |
|
29 wrapper.data = str; |
|
30 return wrapper; |
|
31 } |
|
32 |
|
33 function test() |
|
34 { |
|
35 var data = wrapString("javascript"); |
|
36 var entry = openCacheEntry("javascript", "theme:button"); |
|
37 entry.cacheElement = data; |
|
38 entry.markValid(); |
|
39 entry.close(); |
|
40 |
|
41 var newEntry = openCacheEntry("javascript", "theme:button"); |
|
42 if (newEntry.cacheElement === data) |
|
43 print("object cache works."); |
|
44 else |
|
45 print("object cache failed."); |
|
46 } |
|
47 |
|
48 test(); |