Re: Hashcode/ETag for EOs
Re: Hashcode/ETag for EOs
- Subject: Re: Hashcode/ETag for EOs
- From: Pascal Robert <email@hidden>
- Date: Thu, 26 May 2011 09:20:49 -0400
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 <email@hidden> 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
>>>> email@hidden
>>>>
>>>> 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 (email@hidden)
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>
>>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden