-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support version 3 of the
symfony/cache-contracts
package (#588)
- Loading branch information
Showing
8 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tracing\Cache; | ||
|
||
use Sentry\State\HubInterface; | ||
use Symfony\Component\Cache\Adapter\AdapterInterface; | ||
use Symfony\Component\Cache\PruneableInterface; | ||
use Symfony\Component\Cache\ResettableInterface; | ||
use Symfony\Contracts\Cache\CacheInterface; | ||
|
||
/** | ||
* This implementation of a cache adapter supports the distributed tracing | ||
* feature of Sentry. | ||
* | ||
* @internal | ||
*/ | ||
final class TraceableCacheAdapterForV2 implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface | ||
{ | ||
/** | ||
* @phpstan-use TraceableCacheAdapterTrait<AdapterInterface> | ||
*/ | ||
use TraceableCacheAdapterTrait; | ||
|
||
/** | ||
* @param HubInterface $hub The current hub | ||
* @param AdapterInterface $decoratedAdapter The decorated cache adapter | ||
*/ | ||
public function __construct(HubInterface $hub, AdapterInterface $decoratedAdapter) | ||
{ | ||
$this->hub = $hub; | ||
$this->decoratedAdapter = $decoratedAdapter; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param mixed[] $metadata | ||
* | ||
* @return mixed | ||
*/ | ||
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) | ||
{ | ||
return $this->traceFunction('cache.get_item', function () use ($key, $callback, $beta, &$metadata) { | ||
if (!$this->decoratedAdapter instanceof CacheInterface) { | ||
throw new \BadMethodCallException(sprintf('The %s::get() method is not supported because the decorated adapter does not implement the "%s" interface.', self::class, CacheInterface::class)); | ||
} | ||
|
||
return $this->decoratedAdapter->get($key, $callback, $beta, $metadata); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tracing\Cache; | ||
|
||
use Sentry\State\HubInterface; | ||
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; | ||
use Symfony\Component\Cache\PruneableInterface; | ||
use Symfony\Component\Cache\ResettableInterface; | ||
use Symfony\Contracts\Cache\CacheInterface; | ||
use Symfony\Contracts\Cache\TagAwareCacheInterface; | ||
|
||
/** | ||
* This implementation of a cache adapter aware of cache tags supports the | ||
* distributed tracing feature of Sentry. | ||
* | ||
* @internal | ||
*/ | ||
final class TraceableTagAwareCacheAdapterForV2 implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface | ||
{ | ||
/** | ||
* @phpstan-use TraceableCacheAdapterTrait<TagAwareAdapterInterface> | ||
*/ | ||
use TraceableCacheAdapterTrait; | ||
|
||
/** | ||
* @param HubInterface $hub The current hub | ||
* @param TagAwareAdapterInterface $decoratedAdapter The decorated cache adapter | ||
*/ | ||
public function __construct(HubInterface $hub, TagAwareAdapterInterface $decoratedAdapter) | ||
{ | ||
$this->hub = $hub; | ||
$this->decoratedAdapter = $decoratedAdapter; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param mixed[] $metadata | ||
* | ||
* @return mixed | ||
*/ | ||
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) | ||
{ | ||
return $this->traceFunction('cache.get_item', function () use ($key, $callback, $beta, &$metadata) { | ||
if (!$this->decoratedAdapter instanceof CacheInterface) { | ||
throw new \BadMethodCallException(sprintf('The %s::get() method is not supported because the decorated adapter does not implement the "%s" interface.', self::class, CacheInterface::class)); | ||
} | ||
|
||
return $this->decoratedAdapter->get($key, $callback, $beta, $metadata); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function invalidateTags(array $tags): bool | ||
{ | ||
return $this->traceFunction('cache.invalidate_tags', function () use ($tags): bool { | ||
return $this->decoratedAdapter->invalidateTags($tags); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters