Skip to content

Commit

Permalink
Renamed "Memstatic" to "Memory", updated composer metadata, improved …
Browse files Browse the repository at this point in the history
…`EventManagerInterface::on()` signature
  • Loading branch information
Geolim4 committed Dec 30, 2023
1 parent 035b84a commit d4a52b3
Show file tree
Hide file tree
Showing 33 changed files with 436 additions and 181 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
- Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
- __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 accepts a single `string $events` or an `array $events`.
- Alias `\Phpfastcache\PhpfastcacheEventManager` of `\Phpfastcache\EventManager` has been added to improve your code import readability.
- __Drivers__
- Implemented #906 // **Added `RedisCluster` driver support**
- Driver `Memstatic` has changed its name to `Memory` for more consistency.
- __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.
- __Misc__
- Fixed multiple code typo & updated README.md

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Created `IOConfigurationOption::setPreventCacheSlams()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
- Created `IOConfigurationOption::getCacheSlamsTimeout()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
- Created `IOConfigurationOption::setCacheSlamsTimeout()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
- Method `EventManagerInterface::on(array|string $events, callable $callback)` now accepts a single `string $events` or an `array $events`.


## 4.2.0
Expand Down
25 changes: 14 additions & 11 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ If you discover any vulnerability please be aware of the following table of supp
Then feel free to contact me at the email address provided in the bottom of that page.

## Supported Versions
| Version | End of support | End of life |
| ------- | -------------------- | ------------------ |
| 9.x | December 2023 | December 2024 |
| 8.x | July 2023 | July 2024 |
| 7.1 | July 2021 | July 2022 |
| 7.0 | July 2019 | July 2020 |
| 6.0 | July 2020 | July 2021 |
| 5.0 | July 2018 | July 2019 |
| 4.0 | July 2017 | January 2018 |
| < 4.0 | N/A | N/A |
| Version | End of support | End of life |
|---------|------------------|------------------|
| 10.0 | *In development* | *In development* |
| 9.2 | December 2025 | December 2026 |
| 9.1 | December 2024 | December 2025 |
| 9.0 | December 2023 | December 2024 |
| 8.x | July 2023 | July 2024 |
| 7.1 | July 2021 | July 2022 |
| 7.0 | July 2019 | July 2020 |
| 6.0 | July 2020 | July 2021 |
| 5.0 | July 2018 | July 2019 |
| 4.0 | July 2017 | January 2018 |
| < 4.0 | N/A | N/A |

More details on the [Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV4%CB%96%5D-Global-support-timeline)

## Reporting a Vulnerability
If you discover any security vulnerability contact me at contact#at#geolim4.com with a subject formatted like that:\
`[PHPFASTCACHE][VULNERABILITY] Your subject goes here`
`[PHPFASTCACHE][VULNERABILITY] Your mail subject goes here`

Thanks in advance for taking the time to report me that in private.
2 changes: 1 addition & 1 deletion bin/ci/scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ composer install
#####
# Travis CI have php mongodb extension locked to 1.10, so we must set the mongodb/mongodb minimum version to 1.9 :(
#####
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.39 solarium/solarium:~6.1
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.2 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.39 solarium/solarium:~6.1
26 changes: 22 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","firestore","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","redis cluster","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Solr", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
"homepage": "https://www.phpfastcache.com",
"license": "MIT",
"readme": "README.md",
"minimum-stability": "stable",
"authors": [
{
"name": "Georges.L",
"email": "contact@geolim4.com",
"homepage": "https://github.com/Geolim4",
"role": "Actual Project Manager/Developer"
"role": "Project Manager"
},
{
"name": "Contributors",
Expand All @@ -23,7 +24,16 @@
"psr/cache": "^2.0||^3.0",
"psr/simple-cache": "^2.0||^3.0",
"ext-mbstring": "*",
"ext-json": "*"
"ext-json": "*",
"doctrine/couchdb": "dev-master",
"phpfastcache/phpssdb": "~1.2",
"predis/predis": "~1.1",
"mongodb/mongodb": "~1.9",
"triagens/arangodb": "~3.8",
"aws/aws-sdk-php": "~3.2",
"google/cloud-firestore": "~1.39",
"solarium/solarium": "~6.1",
"symfony/var-dumper": "^6.0"
},
"require-dev": {
"league/climate": "^3.8",
Expand All @@ -35,9 +45,11 @@
},
"suggest": {
"ext-apcu": "*",
"ext-curl": "*",
"ext-intl": "*",
"ext-memcached": "*",
"ext-cassandra": "*",
"ext-grpc": "*",
"ext-memcache": "*",
"ext-mongodb": "*",
"ext-redis": "*",
Expand All @@ -62,14 +74,20 @@
},
"autoload": {
"psr-4": {
"Phpfastcache\\": "lib/Phpfastcache/",
"Phpfastcache\\": "lib/Phpfastcache/"
}
},
"autoload-dev": {
"psr-4": {
"Phpfastcache\\Tests\\": "tests/lib/"
}
},
"support": {
"issues": "https://github.com/PHPSocialNetwork/phpfastcache/issues",
"wiki": "https://github.com/PHPSocialNetwork/phpfastcache/wiki",
"source": "https://github.com/PHPSocialNetwork/phpfastcache"
"docs": "https://github.com/PHPSocialNetwork/phpfastcache/wiki",
"source": "https://github.com/PHPSocialNetwork/phpfastcache",
"security": "https://github.com/PHPSocialNetwork/phpfastcache/blob/master/SECURITY.md"
},
"funding": [
{
Expand Down
10 changes: 10 additions & 0 deletions docs/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ The order of execution of the events is always the following:
- Allow you to alter the parameters built used to create the collection
- **Risky Circular Methods**: None

#### Couchdb (v9.2)
- onCouchdbCreateOptions(*Callable* **$callback**)
- **Callback arguments**
- *ExtendedCacheItemPoolInterface* **$itemPool**
- *EventReferenceParameter($options)* **$options** _via EventReferenceParameter object_ **(type modification forbidden)**
- **Scope**
- Arangodb Driver
- **Description**
- Allow you to alter the options built used to create the Couchdb client instance.
- **Risky Circular Methods**: None
#### Dynamodb
- onDynamodbCreateTable(*Callable* **$callback**)
- **Callback arguments**
Expand Down
4 changes: 2 additions & 2 deletions lib/Phpfastcache/CacheContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct(CacheItemPoolInterface $cacheInstance)
/**
* @throws InvalidArgumentException
*/
public function get(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
public function get(string|\Stringable $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
{
$cacheItem = $this->cacheInstance->getItem($cacheKey);
$cacheItem = $this->cacheInstance->getItem((string) $cacheKey);

if (!$cacheItem->isHit()) {
/*
Expand Down
14 changes: 14 additions & 0 deletions lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,18 @@ public function getHelp(): string
{
return '';
}

/**
* @throws PhpfastcacheInvalidArgumentException
*/
public function throwUnsupportedDriverReadAllPattern(string $linkReference = ''): void
{
throw new PhpfastcacheInvalidArgumentException(
sprintf(
'%s does not support a pattern argument.%s',
$this->getDriverName(),
$linkReference ? " See $linkReference" : ''
)
);
}
}
4 changes: 2 additions & 2 deletions lib/Phpfastcache/Drivers/Arangodb/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
class Config extends ConfigurationOption
{
protected string $database;
protected string $collection;
protected string $database = 'phpfastcache';
protected string $collection = 'phpfastcache';

/**
* @var string|array<string>
Expand Down
5 changes: 4 additions & 1 deletion lib/Phpfastcache/Drivers/Arangodb/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,16 @@ public function getStats(): DriverStatistic
try {
$adminHandler = new AdminHandler($this->instance);
$rawData['adminInfo'] = $adminHandler->getServerVersion(true);

$infoText = \sprintf(
'%s server v%s "%s" edition (%s/%s).',
'%s server v%s "%s" edition (%s/%s). Database/Collection: "%s"/"%s"',
\ucfirst($rawData['adminInfo']['server']),
$rawData['adminInfo']['version'] ?? 'unknown version',
$rawData['adminInfo']['license'] ?? 'unknown licence',
$rawData['adminInfo']['details']['architecture'] ?? 'unknown architecture',
$rawData['adminInfo']['details']['platform'] ?? 'unknown platform',
$this->instance->getDatabase(),
$rawData['collectionInfo']->getName(),
);
} catch (ArangoException $e) {
$infoText = 'No readable human data, encountered an error while trying to get details: ' . $e->getMessage();
Expand Down
75 changes: 67 additions & 8 deletions lib/Phpfastcache/Drivers/Couchdb/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait;
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
use Phpfastcache\Entities\DriverStatistic;
use Phpfastcache\Event\EventReferenceParameter;
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
Expand Down Expand Up @@ -95,13 +96,16 @@ protected function driverConnect(): bool
$url .= ":{$clientConfig->getPort()}";
$url .= '/' . \urlencode($this->getDatabaseName());

$this->instance = CouchDBClient::create(
[
'dbname' => $this->getDatabaseName(),
'url' => $url,
'timeout' => $clientConfig->getTimeout(),
]
);
$options = [
'dbname' => $this->getDatabaseName(),
'url' => $url,
'timeout' => $clientConfig->getTimeout(),
'headers' => []
];

$this->eventManager->dispatch(Event::COUCHDB_CREATE_OPTIONS, $this, new EventReferenceParameter($options));

$this->instance = CouchDBClient::create($options);

$this->createDatabase();

Expand Down Expand Up @@ -164,11 +168,66 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
}

/**
* @param ExtendedCacheItemInterface ...$items
* @return array<array<string, mixed>>
* @throws PhpfastcacheDriverException
*/
protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array
{
$response = $this->instance->findDocuments(
array_map(
fn(string $key) => $this->getCouchDbKey($key),
$this->getKeys($items, true)
)
);

if ($response->status === 404 || empty($response->body['rows'])) {
return [];
}

if ($response->status === 200) {
$driverArrays = [];
foreach ($response->body['rows'] as $row) {
if (isset($row['doc'])) {
$doc = $this->decodeDocument($row['doc']);
$driverArrays[$doc[self::DRIVER_KEY_WRAPPER_INDEX]] = $doc;
}
}
return $driverArrays;
}

throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
}

/**
* @return array<int, string>
* @throws PhpfastcacheDriverException
* @throws PhpfastcacheInvalidArgumentException
*/
protected function driverReadAllKeys(string $pattern = ''): iterable
{
if ($pattern !== '') {
$this->throwUnsupportedDriverReadAllPattern();
}

$response = $this->instance->allDocs(ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT);

if ($response->status === 404 || empty($response->body['rows'])) {
return [];
}

if ($response->status === 200) {
return array_map(static fn(array $row) => $row['doc'][self::DRIVER_KEY_WRAPPER_INDEX], $response->body['rows']);
}

throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
}

/**
* @param ExtendedCacheItemInterface $item
* @return bool
* @throws PhpfastcacheDriverException
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
protected function driverWrite(ExtendedCacheItemInterface $item): bool
Expand Down
8 changes: 8 additions & 0 deletions lib/Phpfastcache/Drivers/Couchdb/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Phpfastcache\Drivers\Couchdb;

class Event extends \Phpfastcache\Event\Event
{
public const COUCHDB_CREATE_OPTIONS = 'CouchdbCreateOptions';
}
2 changes: 1 addition & 1 deletion lib/Phpfastcache/Drivers/Firestore/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
protected function driverReadAllKeys(string $pattern = ''): iterable
{
if ($pattern !== '') {
throw new PhpfastcacheInvalidArgumentException('Firestore does not support a pattern argument');
$this->throwUnsupportedDriverReadAllPattern();
}
$data = [];
$documents = $this->instance->collection($this->getConfig()->getCollectionName())
Expand Down
2 changes: 1 addition & 1 deletion lib/Phpfastcache/Drivers/Memcached/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): arr
protected function driverReadAllKeys(string $pattern = ''): iterable
{
if ($pattern !== '') {
throw new PhpfastcacheInvalidArgumentException('Memcached does not support a pattern argument, see https://www.php.net/manual/en/memcached.getallkeys.php');
$this->throwUnsupportedDriverReadAllPattern('https://www.php.net/manual/en/memcached.getallkeys.php');
}
$keys = $this->instance->getAllKeys();

Expand Down
23 changes: 23 additions & 0 deletions lib/Phpfastcache/Drivers/Memory/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/

declare(strict_types=1);

namespace Phpfastcache\Drivers\Memory;

use Phpfastcache\Config\ConfigurationOption;

class Config extends ConfigurationOption
{
}
Loading

0 comments on commit d4a52b3

Please sign in to comment.