Skip to content

Commit 64f42f9

Browse files
authored
refactor(CachePool): simplify the constructor (#1)
* Fix #1 * Update README * Update VERSION
1 parent c19b28d commit 64f42f9

4 files changed

Lines changed: 13 additions & 17 deletions

File tree

CacheItemPool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Koded\Caching;
44

55
use Exception;
6-
use Koded\Caching\Client\CacheClientFactory;
76
use Psr\Cache\{CacheItemInterface, CacheItemPoolInterface};
87
use function Koded\Stdlib\now;
98

@@ -17,13 +16,14 @@ abstract class CacheItemPool implements CacheItemPoolInterface
1716
private $deferred = [];
1817

1918

20-
abstract public function __construct(CacheClientFactory $factory, string $client);
19+
abstract public function __construct(string $client, array $parameters);
2120

2221
// @codeCoverageIgnoreStart
2322
public function __destruct()
2423
{
2524
$this->commit();
2625
}
26+
2727
// @codeCoverageIgnoreEnd
2828

2929
public function commit(): bool

CachePool.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
namespace Koded\Caching;
44

55
use Exception;
6-
use Koded\Caching\Client\CacheClientFactory;
7-
use Koded\Caching\Configuration\ConfigFactory;
8-
use Psr\Cache\CacheItemPoolInterface;
9-
use Psr\Cache\InvalidArgumentException;
6+
use Psr\Cache\{CacheItemPoolInterface, InvalidArgumentException};
107

118
/**
129
* CachePool creates instances of CacheItemPoolInterface classes.
@@ -44,13 +41,11 @@ public static function use(string $client, array $parameters = []): CacheItemPoo
4441
return self::$instances[$ident];
4542
}
4643

47-
$factory = new CacheClientFactory(new ConfigFactory($parameters));
48-
49-
return self::$instances[$ident] = new class($factory, strtolower($client)) extends CacheItemPool
44+
return self::$instances[$ident] = new class($client, $parameters) extends CacheItemPool
5045
{
51-
public function __construct(CacheClientFactory $factory, string $client)
46+
public function __construct(string $client, array $parameters)
5247
{
53-
$this->client = $factory->new($client);
48+
$this->client = simple_cache_factory($client, $parameters);
5449
}
5550
};
5651
}

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ $cache->save();
5252

5353
**The pool instance is created only once.**
5454

55-
> The `CachePoolFactory` accepts specific parameters for the underlying caching technology.
56-
This library uses the [Koded Simple Cache][koded-cache-simple]. Please see the README in that repository.
55+
> `CachePool::use()` accepts specific parameters for the underlying caching technology.
56+
This method uses the [Koded Simple Cache][koded-cache-simple] package.
57+
Please see the README in that repository for the specific arguments.
5758

58-
You can grab the cache client with
59+
You can grab the cache client if you want to use the client directly
5960

6061
```php
6162
/** $var Psr\SimpleCache\CacheInterface $client */
@@ -65,7 +66,7 @@ $client = $cache->client();
6566
Deferring the items
6667
-------------------
6768

68-
To postpone the cache items saving, and store all items "at once",
69+
To postpone the saving of the cache items (store all items "at once"),
6970
you can use the `saveDeferred()` method. These cache items are saved when you
7071

7172
- execute `commit()`
@@ -102,4 +103,4 @@ The code is distributed under the terms of [The 3-Clause BSD license](LICENSE).
102103
[psr-6]: http://www.php-fig.org/psr/psr-6/
103104
[koded-cache-simple]: https://github.com/kodedphp/cache-simple#configuration-directives
104105
[Redis extension]: https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown
105-
[Memcached extension]: https://github.com/php-memcached-dev/php-memcached
106+
[Memcached extension]: https://github.com/php-memcached-dev/php-memcached

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.1

0 commit comments

Comments
 (0)