8000 [Cache] leverage Contracts\Cache · symfony/symfony@dd9fd32 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd9fd32

Browse files
[Cache] leverage Contracts\Cache
1 parent fe5d5c9 commit dd9fd32

18 files changed

+43
-89
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@
114114
"psr/cache-implementation": "1.0",
115115
"psr/container-implementation": "1.0",
116116
"psr/log-implementation": "1.0",
117-
"psr/simple-cache-implementation": "1.0"
117+
"psr/simple-cache-implementation": "1.0",
118+
"symfony/cache-contracts": "1.0",
119+
"symfony/service-contracts": "1.0",
120+
"symfony/translation-contracts": "1.0"
118121
},
119122
"autoload": {
120123
"psr-4": {

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<service id="Psr\Cache\CacheItemPoolInterface" alias="cache.app" />
150150
<service id="Psr\SimpleCache\CacheInterface" alias="cache.app.simple" />
151151
<service id="Symfony\Component\Cache\Adapter\AdapterInterface" alias="cache.app" />
152-
<service id="Symfony\Component\Cache\CacheInterface" alias="cache.app.taggable" />
152+
<service id="Symfony\Contracts\Cache\CacheInterface" alias="cache.app" />
153+
<service id="Symfony\Contracts\Cache\TagAwareCacheInterface" alias="cache.app.taggable" />
153154
</services>
154155
</container>

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
use Psr\Log\LoggerAwareInterface;
1616
use Psr\Log\LoggerInterface;
1717
use Psr\Log\NullLogger;
18-
use Symfony\Component\Cache\CacheInterface;
1918
use Symfony\Component\Cache\CacheItem;
2019
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2120
use Symfony\Component\Cache\ResettableInterface;
2221
use Symfony\Component\Cache\Traits\AbstractTrait;
2322
use Symfony\Component\Cache\Traits\GetTrait;
23+
use Symfony\Contracts\Cache\CacheInterface;
2424

2525
/**
2626
* @author Nicolas Grekas <p@tchwork.com>

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Log\LoggerAwareInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\ResettableInterface;
1918
use Symfony\Component\Cache\Traits\ArrayTrait;
19+
use Symfony\Contracts\Cache\CacheInterface;
2020

2121
/**
2222
* @author Nicolas Grekas <p@tchwork.com>

src/Symfony/Component/Cache/Adapter/ChainAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1918
use Symfony\Component\Cache\PruneableInterface;
2019
use Symfony\Component\Cache\ResettableInterface;
2120
use Symfony\Component\Cache\Traits\GetTrait;
21+
use Symfony\Contracts\Cache\CacheInterface;
2222
use Symfony\Contracts\Service\ResetInterface;
2323

2424
/**

src/Symfony/Component/Cache/Adapter/NullAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Psr\Cache\CacheItemInterface;
15-
use Symfony\Component\Cache\CacheInterface;
1615
use Symfony\Component\Cache\CacheItem;
16+
use Symfony\Contracts\Cache\CacheInterface;
1717

1818
/**
1919
* @author Titouan Galopin <galopintitouan@gmail.com>

src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1918
use Symfony\Component\Cache\PruneableInterface;
2019
use Symfony\Component\Cache\ResettableInterface;
2120
use Symfony\Component\Cache\Traits\GetTrait;
2221
use Symfony\Component\Cache\Traits\PhpArrayTrait;
22+
use Symfony\Contracts\Cache\CacheInterface;
2323

2424
/**
2525
* Caches items at warm up time using a PHP array that is stored in shared memory by OPCache since PHP 7.0.

src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\CacheItemPoolInterface;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\PruneableInterface;
1918
use Symfony\Component\Cache\ResettableInterface;
2019
use Symfony\Component\Cache\Traits\GetTrait;
2120
use Symfony\Component\Cache\Traits\ProxyTrait;
21+
use Symfony\Contracts\Cache\CacheInterface;
2222

2323
/**
2424
* @author Nicolas Grekas <p@tchwork.com>

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
use Psr\Cache\CacheItemInterface;
1515
use Psr\Cache\InvalidArgumentException;
16-
use Symfony\Component\Cache\CacheInterface;
1716
use Symfony\Component\Cache\CacheItem;
1817
use Symfony\Component\Cache\PruneableInterface;
1918
use Symfony\Component\Cache\ResettableInterface;
2019
use Symfony\Component\Cache\Traits\GetTrait;
2120
use Symfony\Component\Cache\Traits\ProxyTrait;
21+
use Symfony\Contracts\Cache\TagAwareCacheInterface;
2222

2323
/**
2424
* @author Nicolas Grekas <p@tchwork.com>
2525
*/
26-
class TagAwareAdapter implements CacheInterface, TagAwareAdapterInterface, PruneableInterface, ResettableInterface
26+
class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface
2727
{
2828
const TAGS_PREFIX = "\0tags\0";
2929

src/Symfony/Component/Cache/Adapter/TraceableAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Psr\Cache\CacheItemInterface;
15-
use Symfony\Component\Cache\CacheInterface;
1615
use Symfony\Component\Cache\CacheItem;
1716
use Symfony\Component\Cache\PruneableInterface;
1817
use Symfony\Component\Cache\ResettableInterface;
18+
use Symfony\Contracts\Cache\CacheInterface;
1919
use Symfony\Contracts\Service\ResetInterface;
2020

2121
/**

src/Symfony/Component/Cache/Adapter/TraceableTagAwareAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Component\Cache\Adapter;
1313

14-
use Symfony\Component\Cache\CacheInterface;
14+
use Symfony\Contracts\Cache\TagAwareCacheInterface;
1515

1616
/**
1717
* @author Robin Chalas <robin.chalas@gmail.com>
1818
*/
19-
class TraceableTagAwareAdapter extends TraceableAdapter implements CacheInterface, TagAwareAdapterInterface
19+
class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface
2020
{
2121
public function __construct(TagAwareAdapterInterface $pool)
2222
{

src/Symfony/Component/Cache/CacheInterface.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Symfony/Component/Cache/CacheItem.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,16 @@
1111

1212
namespace Symfony\Component\Cache;
1313

14-
use Psr\Cache\CacheItemInterface;
1514
use Psr\Log\LoggerInterface;
1615
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1716
use Symfony\Component\Cache\Exception\LogicException;
17+
use Symfony\Contracts\Cache\ItemInterface;
1818

1919
/**
2020
* @author Nicolas Grekas <p@tchwork.com>
2121
*/
22-
final class CacheItem implements CacheItemInterface
22+
final class CacheItem implements ItemInterface
2323
{
24-
/**
25-
* References the Unix timestamp stating when the item will expire.
26-
*/
27-
const METADATA_EXPIRY = 'expiry';
28-
29-
/**
30-
* References the time the item took to be created, in milliseconds.
31-
*/
32-
const METADATA_CTIME = 'ctime';
33-
34-
/**
35-
* References the list of tags that were assigned to the item, as string[].
36-
*/
37-
const METADATA_TAGS = 'tags';
38-
3924
private const METADATA_EXPIRY_OFFSET = 1527506807;
4025

4126
protected $key;
@@ -118,15 +103,9 @@ public function expiresAfter($time)
118103
}
119104

120105
/**
121-
* Adds a tag to a cache item.
122-
*
123-
* @param string|string[] $tags A tag or array of tags
124-
*
125-
* @return static
126-
*
127-
* @throws InvalidArgumentException When $tag is not valid
106+
* {@inheritdoc}
128107
*/
129-
public function tag($tags)
108+
public function tag($tags): ItemInterface
130109
{
131110
if (!$this->isTaggable) {
132111
throw new LogicException(sprintf('Cache item "%s" comes from a non tag-aware pool: you cannot tag it.', $this->key));
@@ -153,6 +132,14 @@ public function tag($tags)
153132
return $this;
154133
}
155134

135+
/**
136+
* {@inheritdoc}
137+
*/
138+
public function getMetadata(): array
139+
{
140+
return $this->metadata;
141+
}
142+
156143
/**
157144
* Returns the list of tags bound to the value coming from the pool storage if any.
158145
*
@@ -167,16 +154,6 @@ public function getPreviousTags()
167154
return $this->metadata[self::METADATA_TAGS] ?? array();
168155
}
169156

170-
/**
171-
* Returns a list of metadata info that were saved alongside with the cached value.
172-
*
173-
* See public CacheItem::METADATA_* consts for keys potentially found in the returned array.
174-
*/
175-
public function getMetadata(): array
176-
{
177-
return $this->metadata;
178-
}
179-
180157
/**
181158
* Validates a cache key according to PSR-6.
182159
*

src/Symfony/Component/Cache/Exception/LogicException.php

Expand all lines: src/Symfony/Component/Cache/Exception/LogicException.php
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\Cache\Exception;
1313

14-
use Psr\Cache\InvalidArgumentException as Psr6CacheInterface;
15-
use Psr\SimpleCache\InvalidArgumentException as SimpleCacheInterface;
14+
use Psr\Cache\CacheException as Psr6CacheInterface;
15+
use Psr\SimpleCache\CacheException as SimpleCacheInterface;
1616

1717
class LogicException extends \LogicException implements Psr6CacheInterface, SimpleCacheInterface
1818
{

src/Symfony/Component/Cache/Traits/GetTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Cache\CacheItem;
16+
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1617
use Symfony\Component\Cache\LockRegistry;
1718

1819
/**
@@ -31,6 +32,10 @@ trait GetTrait
3132
*/
3233
public function get(string $key, callable $callback, float $beta = null)
3334
{
35+
if (0 > $beta) {
36+
throw new InvalidArgumentException(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', \get_class($this), $beta));
37+
}
38+
3439
return $this->doGet($this, $key, $callback, $beta ?? 1.0);
3540
}
3641

src/Symfony/Component/Cache/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"provide": {
1919
"psr/cache-implementation": "1.0",
20-
"psr/simple-cache-implementation": "1.0"
20+
"psr/simple-cache-implementation": "1.0",
21+
"symfony/cache-contracts": "1.0"
2122
},
2223
"require": {
2324
"php": "^7.1.3",

src/Symfony/Component/DependencyInjection/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"symfony/yaml": "<3.4"
4040
},
4141
"provide": {
42-
"psr/container-implementation": "1.0"
42+
"psr/container-implementation": "1.0",
43+
"symfony/service-contracts": "1.0"
4344
},
4445
"autoload": {
4546
"psr-4": { "Symfony\\Component\\DependencyInjection\\": "" },

src/Symfony/Component/Translation/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"symfony/dependency-injection": "<3.4",
3535
"symfony/yaml": "<3.4"
3636
},
37+
"provide": {
38+
"symfony/translation-contracts": "1.0"
39+
},
3740
"suggest": {
3841
"symfony/config": "",
3942
"symfony/yaml": "",

0 commit comments

Comments
 (0)
0