Re: WebSimpleDB object caching

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 


Nikunj R. Mehta wrote:
> Hi Kris,
>
> Thanks for the insightful feedback.
>
> On Nov 7, 2009, at 8:12 PM, Kris Zyp wrote:
>
>> Is there any intended restrictions on caching of objects returned by
>> queries and gets with WebSimpleDB?
>
> Currently, the spec does specify any required behavior in terms of
> caching objects. As an implementation choice, it would be good if
> the object returned by a database from a cursor can be reused by the
> user agent.
>
>> For example (using the address book
>> example in the spec):
>>
>> |database = window.openDatabase('AddressBook', '1', 'Address Book',
>> true);
>> database.transaction(function(Transaction txn) {
>> var store = txn.getEntityStore('Contact');
>> var allCursor = store.entities();
>> var lCursor = store.getIndex('ContactName').entities('L');
>> var l1 = lCursor.next();
>> l1 = lCursor.next();
>> var l2 = allCursor.next();
>
> From this example, the two calls to lCursor.next() may return the
> exact same object each time even though its contents may be
> completely different. In other words, they could respond positively
> to the identity match '===' but not to the equality match '=='. As a
> spec user which one do you prefer? As spec implementors, what would
> you prefer?
>
>>
>> Now, is there any intended requirement that l1==l2 must be false even
>> if ||they represent the same record (that is l1["id"] === l2["id"]) or
>> can cursors potentially reuse JS objects?
>
> Cursors can potentially reuse JS objects. Would you object if this
> were to be a requirement of the spec?
>
>> Also should store.get(l1.id)
>> == l1 be false as well?
>
> In general, nothing can be said about '==' test, except on
> primitives that are supported by the spec. I currently intend to
> support only String and Number types for use as keys in the spec.
> That means,
>
> store.get(l1.id).id == l1.id but _not_ store.get(l1.id) == l1
>
>> In other words, if one does l2.number =
>> '3322', is there any guarantee that l1.number would be unchanged (or
>> would be changed)?
>
> There is no such guarantee presently. Please explain your
> requirement as that might help shed light on which route to take.
I don't have a hard requirement, we are just using the WebSimpleDB API
as a common interface to different storage system in server side
JavaScript. But, if store.entities().next() !==
store.entities().next() is not guaranteed, it could potentially add an
extra burden on users. If they modify an object return from a cursor,
and have not yet called update or put with it, then it would be
unknown if a future cursor might return the modified object or a fresh
object without the modification. Guaranteeing store.entities().next()
!== store.entities().next() seems like it would provide more
determinism. Alternately, we could guarantee store.entities().next()
=== store.entities().next(), but I don't think you are wanting that,
and it would put extra burden on spec implementors to keep track of
objects that have been returned from cursors.

Presumably the identity guarantee of objects returned from cursors
should be the same as for get(id) calls (if cursors always return a
new JS object, so should get(id)).

Thanks,

- --
Kris Zyp
SitePen
(503) 806-1841
http://sitepen.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iEYEARECAAYFAkr5y+4ACgkQ9VpNnHc4zAweBwCfYEVIuyOwR6epf8Ty4IeV9AT0
NrEAoJgaIz6n9SE8qTor82ZtapaugdGh
=kJxr
-----END PGP SIGNATURE-----

Received on Tuesday, 10 November 2009 20:25:09 UTC