Here's the proposal for Decoupling cache event creation from firing.
The event firing mechanism will essentially be spilt into a two-stage process.
The first being the event creation, where the cache operation creates an event in the ‘apply’ method of the Bi-Function. This event will be added (produced) to an event queue maintained by the CacheEventNotificationService. Now if the said cache operation is successful, i.e. the apply method in Bi-Function returns successfully, the event will be marked `fireable`. At this point the event can be removed from the queue and fired.
The event firing takes place depending on the event ordering configured by the user. Incase of ‘ordered’ firing, a single thread will wait until the event is marked `fireable`, after which it can fire (consume) the events. An event whose `apply` fails to successfully return can be removed from the queue.
The queue here can be something like a `ConcurrentLinkedQueue`, to allow a fast non-blocking access. The queue will however need to have a conditional bound (ConsumerBarrier?) to prevent memory overflow incase of asynchronous-ordered mode, where multiple events are added to the queue but only a single thread has the responsibility of firing them.
|
|
|
|
|
|
|
|
C1 |
|
Event Added
|
|
|
|
|
R1 |
U2 |
U1 |
C1 |
|
Events Marked `Fireable`
|
|
R2 |
U3 |
C3 |
R1 |
U2 |
U1 |
C1 |
|
Worker thread can now remove C1 event from queue and fire it. It will then wait for U1 to become `fireable` before moving to U2
Whereas in case of ‘unordered’ firing, there are two possible approaches:
--
You received this message because you are subscribed to the Google Groups "ehcache-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-dev/2e1f78dc-bab0-49e1-80ba-3f45c0263a41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public AtomicReference<CacheEvent> onEvent(final CacheEvent<K, V> event)