New Posts New Posts RSS Feed: Cache Concurrency
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cache Concurrency

 Post Reply Post Reply
Author
monay View Drop Down
Newbie
Newbie


Joined: 24-Sep-2009
Location: u.s.
Posts: 1
Post Options Post Options   Quote monay Quote  Post ReplyReply Direct Link To This Post Topic: Cache Concurrency
    Posted: 26-Sep-2009 at 2:54am
There is a good example of this in the Classic Tutorials in the "HandlingConcurrency Conflicts" Tutorial.  The other approach is to try and refresh the cache as often as possible from the database.  The obvious problem with this approach is that even if I get fairly recent data, I am not guaranteed to get the very latest and greatest changes.



Edited by GregD - 28-Sep-2009 at 7:27pm
Back to Top
alipoland View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Mar-2009
Location: Poland
Posts: 19
Post Options Post Options   Quote alipoland Quote  Post ReplyReply Direct Link To This Post Posted: 18-May-2009 at 8:03pm
Thank you very much David for the head up, and please do let me know if you have more thought about it.
Thanks for the correction *Concurrency* --> Coherency :)
Peace,
Ali
 
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 18-May-2009 at 9:02am
I have not thought this through in a lot of detail, but it seems that you could create a "Coherency Service" that clients could subscribe to.  When a client changed a value in its cache. it could post the change to the service.  Meanwhile, clients could receive notifications from the service.  To understand how this could be done, look at "Push Notification" tutorials in Classic or "Push Notification" Learning Units in IdeaBlade DevForce.
Back to Top
alipoland View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Mar-2009
Location: Poland
Posts: 19
Post Options Post Options   Quote alipoland Quote  Post ReplyReply Direct Link To This Post Posted: 15-May-2009 at 11:06pm

Thank you David, I got the same info from the developer guide too :)

 

But if I wanted to go the server-notifying-clients-to-refresh-their-caches route? Is EntityLifecycleEvents the way to go and then deal with conflicts on the client-side in the same manner optimistic concurrency does, or is there a simpler way?

 

Please take your time before you answer. If successful I can contribute it back it to IdeaBlade for the benefit of all.

 

ThanQ

 

Ali

God > infinity

Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 15-May-2009 at 4:19pm
DevForce does not try to handle the coherency of all of the client caches.  Rather, it tries to deal with a simpler problem.  How can I make sure that my own cache is consistent with the data in the database.  There are two approaches here.  I can simply try to save the changes in my cache, and then deal with any optimistic concurrency failures that result.  There is a good example of this in the Classic Tutorials in the "HandlingConcurrency Conflicts" Tutorial.  The other approach is to try and refresh the cache as often as possible from the database.  The obvious problem with this approach is that even if I get fairly recent data, I am not guaranteed to get the very latest and greatest changes.
Back to Top
alipoland View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Mar-2009
Location: Poland
Posts: 19
Post Options Post Options   Quote alipoland Quote  Post ReplyReply Direct Link To This Post Posted: 14-May-2009 at 6:45pm

Dear David.

Thanks for pointing out that DevForce can automate the optimistice concurrrency count/timestamp and the FIRST (not last as per your reply, please correct me if I wrong) update wins and all other would get exception on which the developer can refresh her cache.
 
This was not my question however, I need you to tell us how does DevForce help with keeping all caches up-to-date (called cache concurrency).
 
Say I have two sales reps and both need to issue sales orders on the same product and takes them few minutes to complete the sales orders. They need to look at the product quantity available in stock and sell accourdingly. I am asking if there is a simpler way than Object Lifecycle Events to notify the sales rep that is still editing a sales order that the quantity in stock has changes so she can tell the customer to reduce his order.
 
This was a very simple but typical example. In general imagine we develop a stock market game (yes it is a game :) and players need to know at near realtime (not at commit time) what the state of the game is.
 
Any help from DevForce would help all of us I am sure.
 
Thanks.
 
Ali
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 14-May-2009 at 9:37am
Ali, here is what the Developer's Guide says about "optimistic concurrency":
 
Many applications must guard against the possibility that two different users will unknowingly edit and save the same entity simultaneously. Without some kind of checking, the last person to save wins. If I sell a particular item and you sell the same item, we will have sold the same item twice although the database will show only that you sold it.
I could have put a database lock on the item record, thus preventing you from reading and editing it. Such “pessimistic locking” harms performance and leads to troubling lock-out scenarios. Neither DevForce nor the Entity Framework supports such a physical locking scheme.
The Entity Framework relies on “optimistic concurrency” techniques to detect and resolve concurrent access conflicts. Optimistic concurrency assumes that two users rarely wrestle over the same record and therefore allows all users to access records freely. If two users, such as you and I, try to update the same record, it detects the conflict and terminates the second save; it informs the second client be raising a concurrency exception.
The Entity Framework implements optimistic concurrency by comparing the value of a concurrency column in the pending record with the value of that column in the stored record. If the values are the same, the pending record can be saved. If the values are different, the pending record is out of sync with the stored record; the framework assumes a concurrency conflict and throws the exception.
This technique works so long as the concurrency value is changed after each successful save. Who is responsible for that change? The Entity Framework says that you are.
You are fortunate if the database table has an update trigger that can do it. Otherwise, you have to write the code that updates the concurrency column and you have to remember to call it at the right moment.
DevForce can handle the concurrency column update for you. In the DevForce Object Mapper you declare the concurrency column (or columns) and pick a method from a list of concurrency column update methods. DevForce will call that method at the appropriate time. Yes, you can extend the list with a custom method.
Back to Top
alipoland View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Mar-2009
Location: Poland
Posts: 19
Post Options Post Options   Quote alipoland Quote  Post ReplyReply Direct Link To This Post Posted: 14-May-2009 at 9:01am

Salam all,

Can someone please clarifies for me how does DevForce (any version would do) handles cache concurrency? That is when a client holding data in her cache and some other client updates some data that need to be communicated to all affected stale caches, how is that achieved.

 

The only thing comes to mind is Object Lifecycle Events but integrating such functionality into the framework would be the forward solution I believe. Optimistic locking would also be simplified this way as there would be fewer collisions.

 

ThanQ in advance.

 

Ali

<prime numbers are God's signature>

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down