Skip to content

[Cache] leverage Contracts\Cache #28097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@
"psr/cache-implementation": "1.0",
"psr/container-implementation": "1.0",
"psr/log-implementation": "1.0",
"psr/simple-cache-implementation": "1.0"
"psr/simple-cache-implementation": "1.0",
"symfony/cache-contracts": "1.0",
"symfony/service-contracts": "1.0",
"symfony/translation-contracts": "1.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we should add this. OK to you?

},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<service id="Psr\Cache\CacheItemPoolInterface" alias="cache.app" />
<service id="Psr\SimpleCache\CacheInterface" alias="cache.app.simple" />
<service id="Symfony\Component\Cache\Adapter\AdapterInterface" alias="cache.app" />
<service id="Symfony\Component\Cache\CacheInterface" alias="cache.app.taggable" />
<service id="Symfony\Contracts\Cache\CacheInterface" alias="cache.app" />
<service id="Symfony\Contracts\Cache\TagAwareCacheInterface" alias="cache.app.taggable" />
</services>
</container>
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\AbstractTrait;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

use Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerAwareInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\ArrayTrait;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Symfony\Component\Cache\Adapter;

use Psr\Cache\CacheItemInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @author Titouan Galopin <galopintitouan@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Component\Cache\Traits\PhpArrayTrait;
use Symfony\Contracts\Cache\CacheInterface;

/**
* Caches items at warm up time using a PHP array that is stored in shared memory by OPCache since PHP 7.0.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Component\Cache\Traits\ProxyTrait;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

use Psr\Cache\CacheItemInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Component\Cache\Traits\ProxyTrait;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class TagAwareAdapter implements CacheInterface, TagAwareAdapterInterface, PruneableInterface, ResettableInterface
class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface
{
const TAGS_PREFIX = "\0tags\0";

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
namespace Symfony\Component\Cache\Adapter;

use Psr\Cache\CacheItemInterface;
use Symfony\Component\Cache\CacheInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace Symfony\Component\Cache\Adapter;

use Symfony\Component\Cache\CacheInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

/**
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class TraceableTagAwareAdapter extends TraceableAdapter implements CacheInterface, TagAwareAdapterInterface
class TraceableTagAwareAdapter extends TraceableAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface
{
public function __construct(TagAwareAdapterInterface $pool)
{
Expand Down
37 changes: 0 additions & 37 deletions src/Symfony/Component/Cache/CacheInterface.php

This file was deleted.

47 changes: 12 additions & 35 deletions src/Symfony/Component/Cache/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,16 @@

namespace Symfony\Component\Cache;

use Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\Exception\LogicException;
use Symfony\Contracts\Cache\ItemInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
*/
final class CacheItem implements CacheItemInterface
final class CacheItem implements ItemInterface
{
/**
* References the Unix timestamp stating when the item will expire.
*/
const METADATA_EXPIRY = 'expiry';

/**
* References the time the item took to be created, in milliseconds.
*/
const METADATA_CTIME = 'ctime';

/**
* References the list of tags that were assigned to the item, as string[].
*/
const METADATA_TAGS = 'tags';

private const METADATA_EXPIRY_OFFSET = 1527506807;

protected $key;
Expand Down Expand Up @@ -118,15 +103,9 @@ public function expiresAfter($time)
}

/**
* Adds a tag to a cache item.
*
* @param string|string[] $tags A tag or array of tags
*
* @return static
*
* @throws InvalidArgumentException When $tag is not valid
* {@inheritdoc}
*/
public function tag($tags)
public function tag($tags): ItemInterface
{
if (!$this->isTaggable) {
throw new LogicException(sprintf('Cache item "%s" comes from a non tag-aware pool: you cannot tag it.', $this->key));
Expand All @@ -153,6 +132,14 @@ public function tag($tags)
return $this;
}

/**
* {@inheritdoc}
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* Returns the list of tags bound to the value coming from the pool storage if any.
*
Expand All @@ -167,16 +154,6 @@ public function getPreviousTags()
return $this->metadata[self::METADATA_TAGS] ?? array();
}

/**
* Returns a list of metadata info that were saved alongside with the cached value.
*
* See public CacheItem::METADATA_* consts for keys potentially found in the returned array.
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* Validates a cache key according to PSR-6.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Component\Cache\Exception;

use Psr\Cache\InvalidArgumentException as Psr6CacheInterface;
use Psr\SimpleCache\InvalidArgumentException as SimpleCacheInterface;
use Psr\Cache\CacheException as Psr6CacheInterface;
use Psr\SimpleCache\CacheException as SimpleCacheInterface;

class LogicException extends \LogicException implements Psr6CacheInterface, SimpleCacheInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Cache/Traits/GetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\LockRegistry;

/**
Expand All @@ -31,6 +32,10 @@ trait GetTrait
*/
public function get(string $key, callable $callback, float $beta = null)
{
if (0 > $beta) {
throw new InvalidArgumentException(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', \get_class($this), $beta));
}

return $this->doGet($this, $key, $callback, $beta ?? 1.0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"provide": {
"psr/cache-implementation": "1.0",
"psr/simple-cache-implementation": "1.0"
"psr/simple-cache-implementation": "1.0",
"symfony/cache-contracts": "1.0"
},
"require": {
"php": "^7.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"symfony/yaml": "<3.4"
},
"provide": {
"psr/container-implementation": "1.0"
"psr/container-implementation": "1.0",
"symfony/service-contracts": "1.0"
},
"autoload": {
"psr-4": { "Symfony\\Component\\DependencyInjection\\": "" },
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Translation/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"symfony/dependency-injection": "<3.4",
"symfony/yaml": "<3.4"
},
"provide": {
"symfony/translation-contracts": "1.0"
},
"suggest": {
"symfony/config": "",
"symfony/yaml": "",
Expand Down