Skip to content

Commit 6219dd6

Browse files
[Cache] Create PSR-16 variants of all PSR-6 adapters
1 parent 99ae9d6 commit 6219dd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2707
-99
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Traits\ApcuTrait;
15+
16+
class ApcuAdapter extends AbstractAdapter
17+
{
18+
use ApcuTrait;
19+
20+
public function __construct($namespace = '', $defaultLifetime = 0, $version = null)
21+
{
22+
$this->init($namespace, $defaultLifetime, $version);
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Doctrine\Common\Cache\CacheProvider;
15+
use Symfony\Component\Cache\Traits\DoctrineTrait;
16+
17+
class DoctrineAdapter extends AbstractAdapter
18+
{
19+
use DoctrineTrait;
20+
21+
public function __construct(CacheProvider $provider, $namespace = '', $defaultLifetime = 0)
22+
{
23+
parent::__construct('', $defaultLifetime);
24+
$this->provider = $provider;
25+
$provider->setNamespace($namespace);
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Traits\FilesystemTrait;
15+
16+
class FilesystemAdapter extends AbstractAdapter
17+
{
18+
use FilesystemTrait;
19+
20+
public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
21+
{
22+
parent::__construct('', $defaultLifetime);
23+
$this->init($namespace, $directory);
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Traits\MemcachedTrait;
15+
16+
class MemcachedAdapter extends AbstractAdapter
17+
{
18+
use MemcachedTrait;
19+
20+
protected $maxIdLength = 250;
21+
22+
public function __construct(\Memcached $client, $namespace = '', $defaultLifetime = 0)
23+
{
24+
$this->init($client, $namespace, $defaultLifetime);
25+
}
26+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Traits\PdoTrait;
15+
16+
class PdoAdapter extends AbstractAdapter
17+
{
18+
use PdoTrait;
19+
20+
protected $maxIdLength = 255;
21+
22+
/**
23+
* Constructor.
24+
*
25+
* You can either pass an existing database connection as PDO instance or
26+
* a Doctrine DBAL Connection or a DSN string that will be used to
27+
* lazy-connect to the database when the cache is actually used.
28+
*
29+
* List of available options:
30+
* * db_table: The name of the table [default: cache_items]
31+
* * db_id_col: The column where to store the cache id [default: item_id]
32+
* * db_data_col: The column where to store the cache data [default: item_data]
33+
* * db_lifetime_col: The column where to store the lifetime [default: item_lifetime]
34+
* * db_time_col: The column where to store the timestamp [default: item_time]
35+
* * db_username: The username when lazy-connect [default: '']
36+
* * db_password: The password when lazy-connect [default: '']
37+
* * db_connection_options: An array of driver-specific connection options [default: array()]
38+
*
39+
* @param \PDO|Connection|string $connOrDsn A \PDO or Connection instance or DSN string or null
40+
* @param string $namespace
41+
* @param int $defaultLifetime
42+
* @param array $options An associative array of options
43+
*
44+
* @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
45+
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
46+
* @throws InvalidArgumentException When namespace contains invalid characters
47+
*/
48+
public function __construct($connOrDsn, $namespace = '', $defaultLifetime = 0, array $options = array())
49+
{
50+
$this->init($connOrDsn, $namespace, $defaultLifetime, $options);
51+
}
52+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Exception\CacheException;
15+
use Symfony\Component\Cache\Traits\PhpFilesTrait;
16+
17+
class PhpFilesAdapter extends AbstractAdapter
18+
{
19+
use PhpFilesTrait;
20+
21+
public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
22+
{
23+
if (!static::isSupported()) {
24+
throw new CacheException('OPcache is not enabled');
25+
}
26+
parent::__construct('', $defaultLifetime);
27+
$this->init($namespace, $directory);
28+
29+
$e = new \Exception();
30+
$this->includeHandler = function () use ($e) { throw $e; };
31+
}
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Symfony\Component\Cache\Traits\RedisTrait;
15+
16+
class RedisAdapter extends AbstractAdapter
17+
{
18+
use RedisTrait;
19+
20+
/**
21+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
22+
*/
23+
public function __construct($redisClient, $namespace = '', $defaultLifetime = 0)
24+
{
25+
$this->init($redisClient, $namespace, $defaultLifetime);
26+
}
27+
}

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added PSR-16 "Simple Cache" implementations for all existing PSR-6 adapters
8+
* added Psr6Cache and SimpleCacheAdapter for bidirectional interoperability between PSR-6 and PSR-16
9+
* added MemcachedAdapter (PSR-6) and MemcachedCache (PSR-16)
10+
* added TraceableAdapter (PSR-6) and TraceableCache (PSR-16)
11+
412
3.2.0
513
-----
614

0 commit comments

Comments
 (0)