CacheAhead.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Di\Annotation\AbstractAnnotation;
  14. use Hyperf\Di\Annotation\AnnotationCollector;
  15. /**
  16. * Only Support Redis Driver.
  17. */
  18. #[Attribute(Attribute::TARGET_METHOD)]
  19. class CacheAhead extends AbstractAnnotation
  20. {
  21. /**
  22. * @param null|int $ttl the max offset for ttl
  23. * @param bool $runAsync when this method is executed for the first time, the original method is executed asynchronously and cached, so the return value is null
  24. */
  25. public function __construct(
  26. public ?string $prefix = null,
  27. public ?string $value = null,
  28. public ?int $ttl = null,
  29. public int $aheadSeconds = 0,
  30. public int $lockSeconds = 10,
  31. public int $offset = 0,
  32. public string $group = 'default',
  33. public bool $collect = false,
  34. public ?array $skipCacheResults = null,
  35. public bool $runAsync = false,
  36. ) {
  37. }
  38. public function collectMethod(string $className, ?string $target): void
  39. {
  40. AnnotationCollector::collectMethod($className, $target, static::class, $this);
  41. }
  42. }