Skip to content

Commit 92a1048

Browse files
committed
Finalised event docs
1 parent f66d2d8 commit 92a1048

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

docs/EVENTS.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ EventManager::getInstance()->unbindEventCallback('onCacheGetItem', 'myCallbackNa
3535
```
3636

3737

38-
List of active events:
39-
38+
## List of active events:
39+
### ItemPool Events
4040
- onCacheGetItem(*Callable* **$callback**)
4141
- **Callback arguments**
4242
- *ExtendedCacheItemPoolInterface* **$itemPool**
@@ -139,7 +139,40 @@ List of active events:
139139
- *ExtendedCacheItemPoolInterface::getItems()*
140140
- *ExtendedCacheItemPoolInterface::getItemsByTag()*
141141
- *ExtendedCacheItemPoolInterface::getItemsAsJsonString()*
142+
### ItemPool Events (Cluster)
143+
- onCacheReplicationSlaveFallback(*Callable* **$callback**)
144+
- **Callback arguments**
145+
- *ClusterPoolInterface* **$self**
146+
- *string* **$caller**
147+
- **Scope**
148+
- Cluster pool
149+
- **Description**
150+
- Allow you to get notified when a Master/Slave cluster switches on slave
151+
- **Risky Circular Methods**
152+
- N/A
153+
154+
- onCacheReplicationRandomPoolChosen(*Callable* **$callback**)
155+
- **Callback arguments**
156+
- *ClusterPoolInterface* **$self**
157+
- *ExtendedCacheItemPoolInterface* **$randomPool**
158+
- **Scope**
159+
- Cluster pool
160+
- **Description**
161+
- Allow you to get notified when a Random Replication cluster choose a cluster
162+
- **Risky Circular Methods**
163+
- N/A
142164

165+
- onCacheClusterBuilt(*Callable* **$callback**)
166+
- **Callback arguments**
167+
- *AggregatorInterface* **$clusterAggregator**
168+
- *ClusterPoolInterface* **$cluster**
169+
- **Scope**
170+
- Cluster aggregator
171+
- **Description**
172+
- Allow you to get notified when a cluster is being built
173+
- **Risky Circular Methods**
174+
- *$clusterAggregator::getCluster()*
175+
### ItemPool Events
143176
- onCacheItemSet(*Callable* **$callback**)
144177
- **Callback arguments**
145178
- *ExtendedCacheItemInterface* **$item**
@@ -173,4 +206,4 @@ List of active events:
173206
- **Risky Circular Methods**
174207
- *ExtendedCacheItemInterface::expiresAt()*
175208

176-
This is an exhaustive list and it will be updated as soon as new events will be added to the Core.
209+
This is an exhaustive list and it will be updated as soon as new events will be added to the Core.

lib/Phpfastcache/Cluster/ClusterAggregator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ public function getCluster(int $strategy = AggregatorInterface::STRATEGY_FULL_RE
151151

152152
/**
153153
* @eventName CacheClusterBuilt
154-
* @param $_ AggregatablePoolInterface
154+
* @param $clusterAggregator AggregatorInterface
155+
* @param $cluster ClusterPoolInterface
155156
*/
156-
$this->cluster->getEventManager()->dispatch('CacheClusterBuilt', $this->cluster);
157+
$this->cluster->getEventManager()->dispatch('CacheClusterBuilt', $this, $this->cluster);
157158
}
158159
} else {
159160
throw new PhpfastcacheInvalidArgumentException('Unknown cluster strategy');

lib/Phpfastcache/Cluster/Drivers/RandomReplication/RandomReplicationCluster.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function __construct(string $clusterName, ExtendedCacheItemPoolInterface
4141
(new ReflectionMethod(\get_parent_class(\get_parent_class($this)), __FUNCTION__))
4242
->invoke($this, $clusterName, ...$driverPools);
4343
$randomPool = $driverPools[\random_int(0, \count($driverPools) - 1)];
44+
45+
$this->eventManager->dispatch(
46+
'CacheReplicationRandomPoolChosen',
47+
$this,
48+
$randomPool
49+
);
50+
4451
$this->clusterPools = [$randomPool];
4552
}
4653

0 commit comments

Comments
 (0)