In the DataCache API, the "ready" event is the most appropriate place to call swapCache() and update the effective cache. However, the spec outlines a special case for the ready event, which I cannot understand.
- 4.2.2.4 Completing a Transaction
http://dev.w3.org/2006/webapi/DataCache/#complete-transaction
This is the only time the "ready" CacheEvent is queued. There is a special clause, which no other CacheEvent has. It is the "except for the cache host passed to these steps" which concerns me.
[[
7. For each cache host associated with a data cache in cache group, except for the cache host passed to these steps, queue a task to fire an event at the cache host with the name ready, which does not bubble, is not cancelable, and which uses the CacheEvent interface.
]]
Is there a specific reason that the cache host passed into the steps is ignored? If my understanding of that is correct, then given a scenario with multiple cache hosts (window, worker worker); if a user creates a cache transaction on the window's cache host, it would never get the "ready" event. This concerns me.
I would have expected this to be either:
1. normal queue CacheEvent
2. queue 'ready' CacheEvent only on the given cache host
Some other related issues I have with CacheEvents are:
- Event Names and Cache Host Ambiguity
I think "ready" and "error" are overly generic names for events fired on the "cache host". Maybe better names would be "cache-ready" or "cache-error". The specification is also ambiguous on what exactly the "cache host" should be. Claiming:
- it is a Document or Shared Worker
http://dev.w3.org/2006/webapi/DataCache/#cache-host
- it is a Window or WorkerUtils object
http://dev.w3.org/2006/webapi/DataCache/#opening-cache
Since "Window" is used often throughout (including IDLs), I have sided with that.
- 4.1.1. Examples
http://dev.w3.org/2006/webapi/DataCache/#examples
The first example seems to be out of date for a number of reasons.
[[
var uri = ...
var cache = window.openDataCache();
document.body.addEventListener('onready', function(event) {
event.cache.swapCache();
... // take advantage of the new stuff in the cache
});
cache.transaction(function(txn) {
txn.capture(uri);
txn.finish();
});
]]
The issues I see are:
- CacheTransaction.finish does not exist, I raised this point earlier
- document.body.addEventListener why document.body and not the cache host
- addEventListener('onready') I would expect this to just be 'ready' or a better name
I would have expected the example to look more like the following:
----
var uri = ...
var cache = window.openDataCache();
window.addEventListener('cache-ready', function(event) {
event.cache.swapCache();
... // take advantage of the new stuff in the cache
});
cache.transaction(function(txn) {
txn.capture(uri);
txn.commit();
});
----
Cheers,
Joseph Pecoraro