FailCache.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Cache\Annotation;
  12. use Attribute;
  13. use Hyperf\Cache\CacheListenerCollector;
  14. use Hyperf\Di\Annotation\AbstractAnnotation;
  15. use Hyperf\Di\Annotation\AnnotationCollector;
  16. #[Attribute(Attribute::TARGET_METHOD)]
  17. class FailCache extends AbstractAnnotation
  18. {
  19. public function __construct(
  20. public ?string $prefix = null,
  21. public ?string $value = null,
  22. public ?int $ttl = null,
  23. public ?string $listener = null,
  24. public string $group = 'default',
  25. public ?array $skipCacheResults = null
  26. ) {
  27. }
  28. public function collectMethod(string $className, ?string $target): void
  29. {
  30. if (isset($this->listener)) {
  31. CacheListenerCollector::setListener($this->listener, [
  32. 'className' => $className,
  33. 'method' => $target,
  34. ]);
  35. }
  36. AnnotationCollector::collectMethod($className, $target, static::class, $this);
  37. }
  38. }