Skip to content

Commit

Permalink
Rework of events (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Jan 16, 2024
1 parent a30ad45 commit 9448a0c
Show file tree
Hide file tree
Showing 73 changed files with 1,056 additions and 786 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testsv2.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.2', '8.3']
name: PHP ${{ matrix.php-versions }} quality/tests on ${{ matrix.operating-system }}
env:
extensions: mbstring, intl, pdo_sqlite, json, redis, couchbase-3.2.2
Expand Down
197 changes: 12 additions & 185 deletions CHANGELOG.md
@@ -1,189 +1,16 @@
## 9.2.3
##### 11 january 2024
- __Drivers__
- **Added support of `Ravendb` as an extension with its own [sub-repository](https://github.com/PHPSocialNetwork/ravendb-extension).**
- Deprecated `\Phpfastcache\Entities\DriverStatistic::getData()`. Will be removed as of v10.
- Deprecated `\Phpfastcache\Entities\DriverStatistic::setData()`. Will be removed as of v10.
- Added `\Phpfastcache\Entities\DriverStatistic::getCount(): int|null`. If applicable will return the count of cache objects stored in driver database/collection. Null otherwise.
- Added `\Phpfastcache\Entities\DriverStatistic::setCount()`

## 9.2.2
##### 11 january 2024
- __Core__
- Added optional prefix to `\Phpfastcache\Core\Pool\CacheItemPoolTrait::getKeys()`

## 9.2.1
##### 07 january 2024
- __Misc__
- Added additional check in cache manager for extensions

## 9.2.0
##### 07 january 2024
- __API__
- Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
- __Extensions__ (💡 New in 9.2)
- Created an extension mechanism to allow some drivers to be loaded independently, see [README.md](README.md)
- Added support of `Couchbasev4` as an extension with its own [sub-repository](https://github.com/PHPSocialNetwork/couchbasev4-extension).
- **IMPORTANT**: *AS OF v9.2* the following drivers has been **MOVED** to their own sub-repositories as a standalone extension: `Arangodb`, `Couchdb`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`. However `Couchbasev3` will stay in the core for compatibility reasons but will be deprecated.
- **IMPORTANT**: *AS OF v10* extensions will have their namespaces permanently moved from `Phpfastcache\Drivers\EXT_NAME\{Config, Driver, Event, Item}` to `Phpfastcache\Extensions\Drivers\EXT_NAME\{Config, Driver, Event, Item}`. For now an alias is ensuring compatibility.
- __Events__
- EventManager is now scoped to its own poll if retrieved through `ExtendedCacheItemPoolTrait::->getEventManager()`. Global EventManager `EventManager::getInstance()` remains unchanged, see [EVENTS.md](./docs/EVENTS.md).
- `EventManagerInterface::on()` now also accepts a single `string $events`.
- Alias `\Phpfastcache\PhpfastcacheEventManager` of `\Phpfastcache\EventManager` has been added to improve your code import readability.
- Deprecated `\Phpfastcache\Event\EventManagerDispatcherInterface::hasEventManager` to be removed for v10.
- __Drivers__
- Implemented #906 // **Added `RedisCluster` driver support**
- Driver `Memstatic` has changed its name to `Memory` for more consistency.
- Driver `Wincache` is now deprecated and will be removed as of v10 due to the lack of updates to PHP 8 [as officially stated by PHP](https://www.php.net/manual/en/install.windows.recommended.php).
- __Pool__
- Added `ExtendedCacheItemPoolTrait::getAllItems` to allow you to retrieve all items in the cache. This method have some limitations, ([see more in the Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys)).
- __Core__
- Configuration methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()` are deprecated. ([See changes](CHANGELOG_API.md)).
- Fixed #907 // Internal "driver decode()" method will now throw an if the string data looks corrupted.
- Internal: Implemented multiple keys fetch (*if supported by the backend*) to improve the performances behind all `getItems()` calls. Currently only supported in some backends, but it may evolve in the future.
- Internal: Implemented multiple keys delete (*if supported by the backend*) to improve the performances behind all `deleteItems()` calls. Currently only supported in some backends, but it may evolve in the future.
- `\Phpfastcache\CacheContract::get()` now accepts a `\Stringable $cacheKey` argument.
- __Tags__
- Added `\Phpfastcache\Core\Item\TaggableCacheItemInterface::isTagged(): bool`
- __Misc__
- Fixed multiple code typo & updated README.md

## 9.1.3
##### 12 february 2023
- __Core__
- Fixed #893 // getItemsByTag() - empty after one item has expired
- __Misc__
- Fixed multiple code typo & updated README.md

## 9.1.2
##### 09 june 2022
- __API__
- Upgraded Phpfastcache API to `4.2.0` ([see changes](CHANGELOG_API.md))
- __Core__
- Rewrote some core code to improve code maintainability & readability following Scrutinizer and Phpstan recommendations
- Fixed an issue with tags not properly reinitialized when a backend driver returns an expired cache item
- __Drivers__
- Fixed #866 // Deprecated Method Cassandra\ExecutionOptions starting of Cassandra 1.3
- __Misc__
- Increased PHPSTAN level to 6
- Fixed multiple fails of Travis CI
- Migrated Github issue templates from Markdown to YAML configurations

## 9.1.1
##### 15 april 2022
## 10.0.0
##### xx xxxxxxx xxxx
- __Core__
- Fixed #860 // Cache item throw an error on reading with DateTimeImmutable date objects
- Fixed an issue with tags not properly reinitialized when a backend driver returns an expired cache item
- __Drivers__
- Fixed #862 // Multiple driver errors caused by invalid return type of `driverRead()` (reported by @ShockedPlot7560 and @aemla)

## 9.1.0
##### 04 april 2022
- __API__
- Upgraded Phpfastcache API to `4.1.0` ([see changes](CHANGELOG_API.md))
- __Core__
- Added `\Phpfastcache\Helper\UninstanciableObjectTrait` trait which will contains base locked constructor for any classes that are nor meant to be instanciated.
- Deprecated `\Phpfastcache\Config\Config::class`
- Removed/reworked/improved dead/unreachable/redundant/obsolete code, thanks to `Phpstan`
- __Drivers__
- **Added `Solr` driver support**
- __Events__
- Added `\Phpfastcache\Event\EventInterface` for `\Phpfastcache\Event\Event` and subclasses below
- Added `\Phpfastcache\Drivers\Arangodb\Event` for Arangodb events
- Added `\Phpfastcache\Drivers\Dynamodb\Event` for Dynamodb events
- Added `\Phpfastcache\Drivers\Solr\Event` for Solr events
- Moved the following constant from `\Phpfastcache\Event\Event` to their respective drivers: `ARANGODB_CONNECTION`, `ARANGODB_COLLECTION_PARAMS`, `DYNAMODB_CREATE_TABLE`
- __Cluster__
- Fixed #855 // ClusterReplication drivers are saving erroneous expiration date in low-level backends
- __Misc__
- Full PSR-12 compliance is now enforced by PHPCS
- Multiple typo fixes (@mbiebl)
- Updated composer suggestions and CI builder dependencies

## 9.0.2
##### 04 march 2022
- __Core__
- Updated CacheContract::__invoke() signature
- Added new option to allow EventManager override + improved EventManager tests (EventManager::setInstance())
- __Drivers__
- Fixed #853 // Configuration validation issue with Memcached socket (path)
- __Misc__
- Fixed typo and some types hint

## 9.0.1
##### 14 november 2021
- __Core__
- Added `\Phpfastcache\Event\Event` class for centralizing event name with reusable constants.
- __Item__
- `\Psr\Cache\CacheItemInterface::set` will also no longer accepts resource object anymore as method unique parameter
- __Misc__
- Fixed typos in [README.md](./README.md)

## 9.0.0
##### 31 october 2021
- __Migration guide__
- Read the [migration guide](./docs/migration/MigratingFromV8ToV9.md) to upgrade from V8 to V9
- __PSR-6__
- Upgraded `psr/cache` dependency to `^2.0||^3.0` (for PHP-8 types)
- `\Psr\Cache\CacheItemInterface::get()` slightly changed to fully comply with missing PSR-6 specification: If the cache item is **NOT** hit, this method will return `NULL`.
- __PSR-16__
- Upgraded `psr/simple-cache` dependency to `^2.0||^3.0` (for PHP-8 types)
- __API__
- Upgraded Phpfastcache API to `4.0.0` ([see changes](CHANGELOG_API.md))
- Renamed `Api::getPhpFastCacheVersion()` to `Api::getPhpfastcacheVersion()`
- Renamed `Api::getPhpFastCacheChangelog()` to `Api::getPhpfastcacheChangelog()`
- Renamed `Api::getPhpFastCacheGitHeadHash()` to `Api::getPhpfastcacheGitHeadHash()`
- __Cluster__
- Renamed `\Phpfastcache\Cluster\AggregatorInterface::aggregateNewDriver()` to `\Phpfastcache\Cluster\AggregatorInterface::aggregateDriverByName()`
- __Exceptions__
- Added `PhpfastcacheEventManagerException` for EventManager-related exceptions
- __Global__
- Removed magics methods from CacheManager `CacheManager::DriverName()`, use `CacheManager::getInstance('DriverName')` instead
- `\Phpfastcache\Proxy\PhpfastcacheAbstractProxy` now implements `\Phpfastcache\Proxy\PhpfastcacheAbstractProxyInterface`
- Slightly increased performances on some critical points of the library
- Removed "BadPracticeOMeter" notice in CacheManager
- Removed many code duplicate (like in `\Phpfastcache\Driver\[DRIVER_NAME]\Item` classes)
- Reworked traits inter-dependencies for better logic and less polymorphic calls in pool/item traits
- Upgrading library to use benefits of PHP 8 new features (see below)
- Typed every class properties of the library
- Migrated many Closure to arrow functions
- Updated parameters & return type hint to use benefit of covariance and contravariance
- Removed embedded Autoload, Phpfastcache is now only Composer-compatible.
- Removed embedded dependencies (`psr/cache`, `psr/simple-cache`)
- Removed deprecated methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()`. ([See changes](CHANGELOG_API.md)).
Removed deprecated class `\Phpfastcache\Config\Config::class`.
- __Helpers__
- Deprecated `\Phpfastcache\Helper\CacheConditionalHelper`, use `\Phpfastcache\CacheContract` instead
- The `\Phpfastcache\CacheContract` class is now also callable directly without calling `get()` method
- __Config/Options__
- Configuration object will now be locked once the cache pool instance is running.
- Updated `ConfigurationOption` which is no longer an `ArrayObject` class, therefore array-syntax is no longer available.
- Removed configuration entry `htaccess` for files-based drivers.
- Removed `IOConfigurationOptionTrait::getHtaccess()`
- Removed `IOConfigurationOptionTrait::setHtaccess()`
- __Tests__
- Added PHPMD, PHPCS and PHPSTAN coverages to increase quality of the project
- Updated tests to work with new core/drivers changes
- Removed Autoload test since its support has been removed and now only managed by Composer
- Increased tests reliability and code coverage for better catching any eventual regression
- __Item__
- `\Psr\Cache\CacheItemInterface::set` will not accept `\Closure` object anymore as method unique parameter
- Removed `\Phpfastcache\Helper\CacheConditionalHelper`. Use `\Phpfastcache\CacheContract` instead.
- __Drivers__
- Added `Arangodb` driver support
- Added `Dynamodb` (AWS) driver support
- Added `Firestore` (GCP) driver support
- Removed `Cookie` driver because of its potential dangerosity
- Removed `Couchbase` (SDK 2 support dropped) driver which is now replaced by `Couchbasev3` (SDK 3)
- Removed `Devtrue` and `Devfalse` drivers
- Added `Devrandom` with configurable factor chance and data length
- Renamed classes `\Phpfastcache\Cluster\Drivers\[STATEGY]\[CLUSTER_NAME]Cluster` to `\Phpfastcache\Cluster\Drivers\[STATEGY]\Driver` for better driver naming across the project
- Removed deprecated method `\Phpfastcache\Entities\DriverStatistic::getData()`.
- Removed deprecated method `\Phpfastcache\Entities\DriverStatistic::setData()`.
- __Events__
- Added `\Phpfastcache\Event\EventReferenceParameter` class and more events such as driver-specific events, see [EVENTS.md](./docs/EVENTS.md) file for more information
- Event callbacks will now receive the `eventName` as an extra _last_ callback parameter (except for `onEveryEvents` callbacks)
- Added `EventManagerInterface::on(array $eventNames, $callback)` method, to subscribe to multiple events in once with the same callback
- Added method named `unbindAllEventCallbacks(): bool` to `EventManagerInterface` to allow you to unbind/clear all event from an event instance
- Updated argument type #2 (`$items`) of `onCacheSaveMultipleItems()` event from `ExtendedCacheItemInterface[]` to `EventReferenceParameter($items)`
- Updated argument type #2 (`$items`) of `onCacheCommitItem()` event from `ExtendedCacheItemInterface[]` to `EventReferenceParameter($items)`
- Updated argument type #2 (`$value`) of `onCacheItemSet()` event from `mixed` to `EventReferenceParameter(mixed $value)`
- __Misc__
- Increased minimum PHP compatibility in composer to `^8.0`
- Updated copyright headers on every file to include the many project contributors
- Globally renamed every occurrence of `PhpFastCache` to `Phpcastcache`
- Phpfastcache EventManager is now [PSR-14](https://www.php-fig.org/psr/psr-14/) compliant. Therefore, its API has slightly changed and may not be backward-compatible.
- Removed deprecated method `\Phpfastcache\Event\EventManagerDispatcherInterface::hasEventManager`.
- __Drivers__
- Removed driver `Memstatic`. Use `Memory` instead.
- Removed driver `Wincache`.
12 changes: 7 additions & 5 deletions composer.json
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://www.phpfastcache.com",
"license": "MIT",
"readme": "README.md",
"minimum-stability": "stable",
"minimum-stability": "dev",
"authors": [
{
"name": "Georges.L",
Expand All @@ -21,14 +21,16 @@
],
"provide": {
"psr/cache-implementation": "2.0|3.0",
"psr/simple-cache-implementation": "2.0|3.0"
"psr/simple-cache-implementation": "2.0|3.0",
"psr/event-dispatcher-implementation": "^1.0"
},
"require": {
"php": ">=8.0",
"php": ">=8.2",
"psr/cache": "^2.0||^3.0",
"psr/simple-cache": "^2.0||^3.0",
"ext-mbstring": "*",
"ext-json": "*"
"ext-json": "*",
"psr/event-dispatcher": "^1.0"
},
"require-dev": {
"league/climate": "^3.8",
Expand All @@ -37,7 +39,7 @@
"squizlabs/php_codesniffer": "@stable",
"phpstan/phpstan": "@stable",
"jetbrains/phpstorm-stubs": "dev-master",
"phpfastcache/phpfastcache-devtools": "dev-master"
"phpfastcache/phpfastcache-devtools": "^10.0.0-ALPHA"
},
"suggest": {
"ext-apcu": "*",
Expand Down
5 changes: 3 additions & 2 deletions lib/Phpfastcache/Cluster/ClusterAggregator.php
Expand Up @@ -19,7 +19,8 @@
use Exception;
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
use Phpfastcache\Event\Event;
use Phpfastcache\Event\Event\CacheItemPoolEventClusterBuilt;
use Phpfastcache\Event\Events;
use Phpfastcache\EventManager;
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
Expand Down Expand Up @@ -151,7 +152,7 @@ public function getCluster(int $strategy = AggregatorInterface::STRATEGY_FULL_RE
...\array_values($this->driverPools)
);

$this->cluster->getEventManager()->dispatch(Event::CACHE_CLUSTER_BUILT, $this, $this->cluster);
$this->cluster->getEventManager()->dispatch(new CacheItemPoolEventClusterBuilt($this->cluster, $this));
}
} else {
throw new PhpfastcacheInvalidArgumentException('Unknown cluster strategy');
Expand Down
10 changes: 0 additions & 10 deletions lib/Phpfastcache/Cluster/ClusterPoolAbstract.php
Expand Up @@ -235,16 +235,6 @@ public function getStats(): DriverStatistic
)
);

$stats->setData(
\implode(
', ',
\array_map(
static fn (ExtendedCacheItemPoolInterface $pool) => $pool->getStats()->getData(),
$this->clusterPools
)
)
);

return $stats;
}
}
Expand Up @@ -20,7 +20,7 @@
use Phpfastcache\Cluster\ClusterPoolAbstract;
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
use Phpfastcache\Event\Event;
use Phpfastcache\Event\Event\CacheReplicationSlaveFallbackItemPoolEvent;
use Phpfastcache\Event\EventManagerInterface;
use Phpfastcache\Exceptions\PhpfastcacheCoreException;
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
Expand Down Expand Up @@ -80,9 +80,10 @@ protected function makeOperation(callable $operation)
} catch (PhpfastcacheExceptionInterface $e) {
try {
$this->eventManager->dispatch(
Event::CACHE_REPLICATION_SLAVE_FALLBACK,
$this,
\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function']
new CacheReplicationSlaveFallbackItemPoolEvent(
$this,
\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function']
)
);
return $operation($this->getSlavePool());
} catch (PhpfastcacheExceptionInterface $e) {
Expand Down
10 changes: 6 additions & 4 deletions lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php
Expand Up @@ -18,7 +18,8 @@

use Phpfastcache\Cluster\AggregatablePoolInterface;
use Phpfastcache\Cluster\Drivers\MasterSlaveReplication\Driver as MasterSlaveReplicationDriver;
use Phpfastcache\Event\Event;
use Phpfastcache\Event\Event\CacheReplicationRandomPoolChosenItemPoolEvent;
use Phpfastcache\Event\Events;
use Phpfastcache\Event\EventManagerInterface;
use ReflectionException;
use ReflectionMethod;
Expand Down Expand Up @@ -46,9 +47,10 @@ public function __construct(
$randomPool = $driverPools[\random_int(0, \count($driverPools) - 1)];

$this->eventManager->dispatch(
Event::CACHE_REPLICATION_RANDOM_POOL_CHOSEN,
$this,
$randomPool
new CacheReplicationRandomPoolChosenItemPoolEvent(
$this,
$randomPool
)
);

$this->clusterPools = [$randomPool];
Expand Down
36 changes: 0 additions & 36 deletions lib/Phpfastcache/Config/Config.php

This file was deleted.

0 comments on commit 9448a0c

Please sign in to comment.