Re: Hashcode/ETag for EOs
Le 2011-05-29 à 14:51, Farrukh Ijaz a écrit : > Hi Pascal, > > On 2011-05-29, at 9:20 PM, Pascal Robert wrote: > >> I did : >> >> ERXRouteResults results = (ERXRouteResults)response(someEntity, filter); >> String etagHash = >> ERXCrypto.sha256Encode(results.responseNode().toString(results.format(), >> this.restContext())); > > IMO, this is an expensive approach because of encryption algorithm. Unless > encryption of the data is key requirement, don't use it. I only need a hash. Base64 or MD5 would be ok too. > Because normally the toString() if not overridden returns a String comprising > the memory address of the instance, this is the reason a simple hashCode() > call is not sufficient in your case. You can simply override the hashCode() > method and compute the values based on your entity attributes. The problem is that it had to be compute from the attributes that are part of the (ERXKeyFilter) filter. And I do think it should be using the format requested too, so that if someone ask for a JSON representation and someone ask for a XML one, the ETag would be different. But we can debate on that, because I'm not 100% sure that the same object but using represented in a different format should have a different ETag. > For caching use Hashtable but that will only benefit if your hashCode() > generates unique value. In my experience the best way to cache the values is > to maintain a binary tree using the hashCode() as the node value. If you want > to implement a better caching, try exploring Splay tree model. With a little > modification to it, you can make you caching super fast. > > These things are not normally practiced by API users but they do matter is > you develop your own API to be used by someone else :) > > Farrukh > >> >>> there's not a direct simple way to do it ... probably grab the snapshot off >>> the EO and compute a hash of the values (you can ignore the keys because >>> they're fixed). it might be something where you can make a new interface in >>> ERX that your EO's could implement to provide a more optimal impl (like >>> ERCStamped could use its lastModified as a basis). >>> >>> ms >>> >>> On May 25, 2011, at 1:55 PM, Pascal Robert wrote: >>> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can be done for REST services. What I want to do is to have the same ETag value for each representation of the EO, so when one of the values change, the ETag value will also change, but if the EO have the same value, it will generate the same ETag as another request got. Problem is: I don't know what to use. I tried with myEO.hashCode() but I did some tests and every time I fetch the EO, the hashcode is different even if the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, but I was wondering if another way exist? I could use a "last modified" date and generate a MD5 of that too, but that date is a better option for the Last-Modified header. -- Pascal Robert prob...@macti.ca WOWODC 2011 : July 1-2-3, Montreal. wowodc.com AIM/iChat : MacTICanada LinkedIn : http://www.linkedin.com/in/macti Twitter : pascal_robert ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com This email sent to msch...@pobox.com >>> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/farrukh.ijaz%40fuegodigitalmedia.com >> >> This email sent to farrukh.i...@fuegodigitalmedia.com > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Hi Pascal, On 2011-05-29, at 9:20 PM, Pascal Robert wrote: > I did : > >ERXRouteResults results = (ERXRouteResults)response(someEntity, filter); >String etagHash = > ERXCrypto.sha256Encode(results.responseNode().toString(results.format(), > this.restContext())); IMO, this is an expensive approach because of encryption algorithm. Unless encryption of the data is key requirement, don't use it. Because normally the toString() if not overridden returns a String comprising the memory address of the instance, this is the reason a simple hashCode() call is not sufficient in your case. You can simply override the hashCode() method and compute the values based on your entity attributes. For caching use Hashtable but that will only benefit if your hashCode() generates unique value. In my experience the best way to cache the values is to maintain a binary tree using the hashCode() as the node value. If you want to implement a better caching, try exploring Splay tree model. With a little modification to it, you can make you caching super fast. These things are not normally practiced by API users but they do matter is you develop your own API to be used by someone else :) Farrukh > >> there's not a direct simple way to do it ... probably grab the snapshot off >> the EO and compute a hash of the values (you can ignore the keys because >> they're fixed). it might be something where you can make a new interface in >> ERX that your EO's could implement to provide a more optimal impl (like >> ERCStamped could use its lastModified as a basis). >> >> ms >> >> On May 25, 2011, at 1:55 PM, Pascal Robert wrote: >> >>> I'm trying to find a way to generate a HTTP ETag for EOs so that caching >>> can be done for REST services. What I want to do is to have the same ETag >>> value for each representation of the EO, so when one of the values change, >>> the ETag value will also change, but if the EO have the same value, it will >>> generate the same ETag as another request got. >>> >>> Problem is: I don't know what to use. I tried with myEO.hashCode() but I >>> did some tests and every time I fetch the EO, the hashcode is different >>> even if the data didn't change. I'm thinking of doing a MD5 digest of part >>> of the EO, but I was wondering if another way exist? I could use a "last >>> modified" date and generate a MD5 of that too, but that date is a better >>> option for the Last-Modified header. >>> >>> -- >>> Pascal Robert >>> prob...@macti.ca >>> >>> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >>> >>> AIM/iChat : MacTICanada >>> LinkedIn : http://www.linkedin.com/in/macti >>> Twitter : pascal_robert >>> >>> >>> >>> ___ >>> Do not post admin requests to the list. They will be ignored. >>> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >>> Help/Unsubscribe/Update your Subscription: >>> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com >>> >>> This email sent to msch...@pobox.com >> > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/farrukh.ijaz%40fuegodigitalmedia.com > > This email sent to farrukh.i...@fuegodigitalmedia.com ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
I did : ERXRouteResults results = (ERXRouteResults)response(someEntity, filter); String etagHash = ERXCrypto.sha256Encode(results.responseNode().toString(results.format(), this.restContext())); > there's not a direct simple way to do it ... probably grab the snapshot off > the EO and compute a hash of the values (you can ignore the keys because > they're fixed). it might be something where you can make a new interface in > ERX that your EO's could implement to provide a more optimal impl (like > ERCStamped could use its lastModified as a basis). > > ms > > On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? I could use a "last modified" >> date and generate a MD5 of that too, but that date is a better option for >> the Last-Modified header. >> >> -- >> Pascal Robert >> prob...@macti.ca >> >> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >> >> AIM/iChat : MacTICanada >> LinkedIn : http://www.linkedin.com/in/macti >> Twitter : pascal_robert >> >> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com >> >> This email sent to msch...@pobox.com > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
BTW, this is to do "Optimistic Locking for REST", for cases like this: Both Client A and Client B ask for the same data: --> GET /some/data.json HTTP/1.1 <-- Date: 25 May 2011 14:00:00 GMT <-- HTTP/1.1 200 Ok <-- Last-Modified: 25 May 2011 13:02:30 GMT <-- Expires: 25 May 2011 15:00:00 GMT <-- { someData } Client A send an update: --> PUT /some/data.json HTTP/1.1 --> If-Unmodified-Since: 25 May 2011 13:02:30 GMT { someAttribute: 'blabla from client A', id: 1, type: 'SomeEntity' } -> Last-Modified on the representation before the update is 25 May 2011 13:02:30 GMT, so we are good to go <- <-- HTTP/1.1 200 OK <-- Last-Modified: 25 May 2011 14:05:30 GMT <-- { someData } Client B send an update: --> PUT /some/data.json HTTP/1.1 --> If-Unmodified-Since: 25 May 2011 13:02:30 GMT { someAttribute: 'blabla from client B', id: 1, type: 'SomeEntity' } -> BUSTED! Last-Modified on the representation is now 25 May 2011 14:05:30 because of Client A update! <- <-- HTTP/1.1 412 Precondition Failed <-- { error: 'Ya man, someone before you updated the same object' } > Errest should be using some new method on the rest delegate probably, whose > default impl is to check for that interface on the object and then fall back > to something hashcodey > > Sent from my iPhone > > On May 25, 2011, at 2:14 PM, Pascal Robert wrote: > >> Ah, ERCStamped is fantastic for generating the Last-Modified header! Some >> day, I will have two weeks off just to look at all the stuff in Wonder... >> >>> there's not a direct simple way to do it ... probably grab the snapshot off >>> the EO and compute a hash of the values (you can ignore the keys because >>> they're fixed). it might be something where you can make a new interface in >>> ERX that your EO's could implement to provide a more optimal impl (like >>> ERCStamped could use its lastModified as a basis). >>> >>> ms >>> >>> On May 25, 2011, at 1:55 PM, Pascal Robert wrote: >>> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can be done for REST services. What I want to do is to have the same ETag value for each representation of the EO, so when one of the values change, the ETag value will also change, but if the EO have the same value, it will generate the same ETag as another request got. Problem is: I don't know what to use. I tried with myEO.hashCode() but I did some tests and every time I fetch the EO, the hashcode is different even if the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, but I was wondering if another way exist? I could use a "last modified" date and generate a MD5 of that too, but that date is a better option for the Last-Modified header. -- Pascal Robert prob...@macti.ca WOWODC 2011 : July 1-2-3, Montreal. wowodc.com AIM/iChat : MacTICanada LinkedIn : http://www.linkedin.com/in/macti Twitter : pascal_robert ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com This email sent to msch...@pobox.com >>> >> ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
NSDictionary's hashcode is very bad ... you wouldn't want to use that for your etag. ms On May 25, 2011, at 2:03 PM, Jean-Francois Veillette wrote: > > Le 2011-05-25 à 13:55, Pascal Robert a écrit : > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? > > myEO.snapshotDictionary().hashCode() ? > That would be based on the attributes values only. > hmmm ... not sure how it would deal with relationship though (with regards to > faulting). > > >> I could use a "last modified" date and generate a MD5 of that too, but that >> date is a better option for the Last-Modified header. > > > jfv > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com > > This email sent to msch...@pobox.com ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Le 2011-05-25 à 13:55, Pascal Robert a écrit : > I'm trying to find a way to generate a HTTP ETag for EOs so that caching can > be done for REST services. What I want to do is to have the same ETag value > for each representation of the EO, so when one of the values change, the ETag > value will also change, but if the EO have the same value, it will generate > the same ETag as another request got. > > Problem is: I don't know what to use. I tried with myEO.hashCode() but I did > some tests and every time I fetch the EO, the hashcode is different even if > the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, > but I was wondering if another way exist? myEO.snapshotDictionary().hashCode() ? That would be based on the attributes values only. hmmm ... not sure how it would deal with relationship though (with regards to faulting). > I could use a "last modified" date and generate a MD5 of that too, but that > date is a better option for the Last-Modified header. jfv ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
lol Sent from my iPhone On May 25, 2011, at 2:27 PM, David Avendasora wrote: > Sent from my Mac, where I have all of the Wonder source code and still can't > outdo Mike with just his memory of the codebase. ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Errest should be using some new method on the rest delegate probably, whose default impl is to check for that interface on the object and then fall back to something hashcodey Sent from my iPhone On May 25, 2011, at 2:14 PM, Pascal Robert wrote: > Ah, ERCStamped is fantastic for generating the Last-Modified header! Some > day, I will have two weeks off just to look at all the stuff in Wonder... > >> there's not a direct simple way to do it ... probably grab the snapshot off >> the EO and compute a hash of the values (you can ignore the keys because >> they're fixed). it might be something where you can make a new interface in >> ERX that your EO's could implement to provide a more optimal impl (like >> ERCStamped could use its lastModified as a basis). >> >> ms >> >> On May 25, 2011, at 1:55 PM, Pascal Robert wrote: >> >>> I'm trying to find a way to generate a HTTP ETag for EOs so that caching >>> can be done for REST services. What I want to do is to have the same ETag >>> value for each representation of the EO, so when one of the values change, >>> the ETag value will also change, but if the EO have the same value, it will >>> generate the same ETag as another request got. >>> >>> Problem is: I don't know what to use. I tried with myEO.hashCode() but I >>> did some tests and every time I fetch the EO, the hashcode is different >>> even if the data didn't change. I'm thinking of doing a MD5 digest of part >>> of the EO, but I was wondering if another way exist? I could use a "last >>> modified" date and generate a MD5 of that too, but that date is a better >>> option for the Last-Modified header. >>> >>> -- >>> Pascal Robert >>> prob...@macti.ca >>> >>> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >>> >>> AIM/iChat : MacTICanada >>> LinkedIn : http://www.linkedin.com/in/macti >>> Twitter : pascal_robert >>> >>> >>> >>> ___ >>> Do not post admin requests to the list. They will be ignored. >>> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >>> Help/Unsubscribe/Update your Subscription: >>> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com >>> >>> This email sent to msch...@pobox.com >> > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
On May 25, 2011, at 2:24 PM, Mike Schrag wrote: > Wait .. What? Why? I thought I covered that: "If I never try to upstage (Mike) then it'll never happen, right?!" > Use the eo's snapshot. Well sure, when you say it like that, my idea sounds stupid. :-) > Sent from my iPhone Sent from my Mac, where I have all of the Wonder source code and still can't outdo Mike with just his memory of the codebase. > > On May 25, 2011, at 2:20 PM, David Avendasora > wrote: > >> I'm guessing this will trigger another round-trip to the db, but what about >> adding this to your EOGenericRecord subclass: >> >> public int rawHashCode() { >> return EOUtilities.rawRowsMatchingKeyAndValue(editingContext(), >> Identity.ENTITY_NAME, >> ID_KEY, >> primaryKey()) >> .lastObject() >> .hashCode(); >> } >> >> Obviously, getting the value at a higher level would be better, but does >> this at least return the same hashCode for every fetch? >> >> Of course, Mike's ERCStamped solution is probably better with less overhead, >> but what the heck. If I never try to upstage him then it'll never happen, >> right?! >> >> Dave >> >> On May 25, 2011, at 1:55 PM, Pascal Robert wrote: >> >>> I'm trying to find a way to generate a HTTP ETag for EOs so that caching >>> can be done for REST services. What I want to do is to have the same ETag >>> value for each representation of the EO, so when one of the values change, >>> the ETag value will also change, but if the EO have the same value, it will >>> generate the same ETag as another request got. >>> >>> Problem is: I don't know what to use. I tried with myEO.hashCode() but I >>> did some tests and every time I fetch the EO, the hashcode is different >>> even if the data didn't change. I'm thinking of doing a MD5 digest of part >>> of the EO, but I was wondering if another way exist? I could use a "last >>> modified" date and generate a MD5 of that too, but that date is a better >>> option for the Last-Modified header. >>> >>> -- >>> Pascal Robert >>> prob...@macti.ca >>> >>> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >>> >>> AIM/iChat : MacTICanada >>> LinkedIn : http://www.linkedin.com/in/macti >>> Twitter : pascal_robert >>> >>> >>> >>> ___ >>> Do not post admin requests to the list. They will be ignored. >>> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >>> Help/Unsubscribe/Update your Subscription: >>> http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com >>> >>> This email sent to webobje...@avendasora.com >>> >>> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com >> >> This email sent to msch...@pobox.com > > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Or in your example, gid.hashcode but you don't want that for an etag. Sent from my iPhone On May 25, 2011, at 2:20 PM, David Avendasora wrote: > I'm guessing this will trigger another round-trip to the db, but what about > adding this to your EOGenericRecord subclass: > >public int rawHashCode() { >return EOUtilities.rawRowsMatchingKeyAndValue(editingContext(), > Identity.ENTITY_NAME, > ID_KEY, > primaryKey()) > .lastObject() > .hashCode(); >} > > Obviously, getting the value at a higher level would be better, but does this > at least return the same hashCode for every fetch? > > Of course, Mike's ERCStamped solution is probably better with less overhead, > but what the heck. If I never try to upstage him then it'll never happen, > right?! > > Dave > > On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? I could use a "last modified" >> date and generate a MD5 of that too, but that date is a better option for >> the Last-Modified header. >> >> -- >> Pascal Robert >> prob...@macti.ca >> >> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >> >> AIM/iChat : MacTICanada >> LinkedIn : http://www.linkedin.com/in/macti >> Twitter : pascal_robert >> >> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com >> >> This email sent to webobje...@avendasora.com >> >> > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com > > This email sent to msch...@pobox.com ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Wait .. What? Why? Use the eo's snapshot. Sent from my iPhone On May 25, 2011, at 2:20 PM, David Avendasora wrote: > I'm guessing this will trigger another round-trip to the db, but what about > adding this to your EOGenericRecord subclass: > >public int rawHashCode() { >return EOUtilities.rawRowsMatchingKeyAndValue(editingContext(), > Identity.ENTITY_NAME, > ID_KEY, > primaryKey()) > .lastObject() > .hashCode(); >} > > Obviously, getting the value at a higher level would be better, but does this > at least return the same hashCode for every fetch? > > Of course, Mike's ERCStamped solution is probably better with less overhead, > but what the heck. If I never try to upstage him then it'll never happen, > right?! > > Dave > > On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? I could use a "last modified" >> date and generate a MD5 of that too, but that date is a better option for >> the Last-Modified header. >> >> -- >> Pascal Robert >> prob...@macti.ca >> >> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >> >> AIM/iChat : MacTICanada >> LinkedIn : http://www.linkedin.com/in/macti >> Twitter : pascal_robert >> >> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com >> >> This email sent to webobje...@avendasora.com >> >> > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com > > This email sent to msch...@pobox.com ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
On May 25, 2011, at 2:20 PM, David Avendasora wrote: > I'm guessing this will trigger another round-trip to the db, but what about > adding this to your EOGenericRecord subclass: > >public int rawHashCode() { >return EOUtilities.rawRowsMatchingKeyAndValue(editingContext(), > Identity.ENTITY_NAME, > ID_KEY, > primaryKey()) > .lastObject() > .hashCode(); >} > > Obviously, getting the value at a higher level would be better, but does this > at least return the same hashCode for every fetch? > > Of course, Mike's ERCStamped solution is probably better with less overhead, > but what the heck. If I never try to upstage him then it'll never happen, > right?! Well, and the fact that it won't work for EOs with compound PKs... but nobody does that, right? > > Dave > > On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? I could use a "last modified" >> date and generate a MD5 of that too, but that date is a better option for >> the Last-Modified header. >> >> -- >> Pascal Robert >> prob...@macti.ca >> >> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >> >> AIM/iChat : MacTICanada >> LinkedIn : http://www.linkedin.com/in/macti >> Twitter : pascal_robert >> >> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com >> >> This email sent to webobje...@avendasora.com >> >> > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com > > This email sent to webobje...@avendasora.com > > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
I'm guessing this will trigger another round-trip to the db, but what about adding this to your EOGenericRecord subclass: public int rawHashCode() { return EOUtilities.rawRowsMatchingKeyAndValue(editingContext(), Identity.ENTITY_NAME, ID_KEY, primaryKey()) .lastObject() .hashCode(); } Obviously, getting the value at a higher level would be better, but does this at least return the same hashCode for every fetch? Of course, Mike's ERCStamped solution is probably better with less overhead, but what the heck. If I never try to upstage him then it'll never happen, right?! Dave On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > I'm trying to find a way to generate a HTTP ETag for EOs so that caching can > be done for REST services. What I want to do is to have the same ETag value > for each representation of the EO, so when one of the values change, the ETag > value will also change, but if the EO have the same value, it will generate > the same ETag as another request got. > > Problem is: I don't know what to use. I tried with myEO.hashCode() but I did > some tests and every time I fetch the EO, the hashcode is different even if > the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, > but I was wondering if another way exist? I could use a "last modified" date > and generate a MD5 of that too, but that date is a better option for the > Last-Modified header. > > -- > Pascal Robert > prob...@macti.ca > > WOWODC 2011 : July 1-2-3, Montreal. wowodc.com > > AIM/iChat : MacTICanada > LinkedIn : http://www.linkedin.com/in/macti > Twitter : pascal_robert > > > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com > > This email sent to webobje...@avendasora.com > > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
Ah, ERCStamped is fantastic for generating the Last-Modified header! Some day, I will have two weeks off just to look at all the stuff in Wonder... > there's not a direct simple way to do it ... probably grab the snapshot off > the EO and compute a hash of the values (you can ignore the keys because > they're fixed). it might be something where you can make a new interface in > ERX that your EO's could implement to provide a more optimal impl (like > ERCStamped could use its lastModified as a basis). > > ms > > On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > >> I'm trying to find a way to generate a HTTP ETag for EOs so that caching can >> be done for REST services. What I want to do is to have the same ETag value >> for each representation of the EO, so when one of the values change, the >> ETag value will also change, but if the EO have the same value, it will >> generate the same ETag as another request got. >> >> Problem is: I don't know what to use. I tried with myEO.hashCode() but I did >> some tests and every time I fetch the EO, the hashcode is different even if >> the data didn't change. I'm thinking of doing a MD5 digest of part of the >> EO, but I was wondering if another way exist? I could use a "last modified" >> date and generate a MD5 of that too, but that date is a better option for >> the Last-Modified header. >> >> -- >> Pascal Robert >> prob...@macti.ca >> >> WOWODC 2011 : July 1-2-3, Montreal. wowodc.com >> >> AIM/iChat : MacTICanada >> LinkedIn : http://www.linkedin.com/in/macti >> Twitter : pascal_robert >> >> >> >> ___ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com >> >> This email sent to msch...@pobox.com > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Hashcode/ETag for EOs
there's not a direct simple way to do it ... probably grab the snapshot off the EO and compute a hash of the values (you can ignore the keys because they're fixed). it might be something where you can make a new interface in ERX that your EO's could implement to provide a more optimal impl (like ERCStamped could use its lastModified as a basis). ms On May 25, 2011, at 1:55 PM, Pascal Robert wrote: > I'm trying to find a way to generate a HTTP ETag for EOs so that caching can > be done for REST services. What I want to do is to have the same ETag value > for each representation of the EO, so when one of the values change, the ETag > value will also change, but if the EO have the same value, it will generate > the same ETag as another request got. > > Problem is: I don't know what to use. I tried with myEO.hashCode() but I did > some tests and every time I fetch the EO, the hashcode is different even if > the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, > but I was wondering if another way exist? I could use a "last modified" date > and generate a MD5 of that too, but that date is a better option for the > Last-Modified header. > > -- > Pascal Robert > prob...@macti.ca > > WOWODC 2011 : July 1-2-3, Montreal. wowodc.com > > AIM/iChat : MacTICanada > LinkedIn : http://www.linkedin.com/in/macti > Twitter : pascal_robert > > > > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com > > This email sent to msch...@pobox.com ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Hashcode/ETag for EOs
I'm trying to find a way to generate a HTTP ETag for EOs so that caching can be done for REST services. What I want to do is to have the same ETag value for each representation of the EO, so when one of the values change, the ETag value will also change, but if the EO have the same value, it will generate the same ETag as another request got. Problem is: I don't know what to use. I tried with myEO.hashCode() but I did some tests and every time I fetch the EO, the hashcode is different even if the data didn't change. I'm thinking of doing a MD5 digest of part of the EO, but I was wondering if another way exist? I could use a "last modified" date and generate a MD5 of that too, but that date is a better option for the Last-Modified header. -- Pascal Robert prob...@macti.ca WOWODC 2011 : July 1-2-3, Montreal. wowodc.com AIM/iChat : MacTICanada LinkedIn : http://www.linkedin.com/in/macti Twitter : pascal_robert ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com