RedisCache.php 1008 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Facades;
  3. use App\Services\RedisCacheFake;
  4. use Illuminate\Support\Facades\Facade;
  5. /**
  6. * 业务代码用的缓存门面,取代 Illuminate\Support\Facades\Cache。
  7. *
  8. * @method static mixed get(string $key, mixed $default = null)
  9. * @method static bool put(string $key, mixed $value, \DateTimeInterface|\DateInterval|int|null $ttl = null)
  10. * @method static mixed remember(string $key, \DateTimeInterface|\DateInterval|int|null $ttl, \Closure $callback)
  11. * @method static bool has(string $key)
  12. * @method static bool forget(string $key)
  13. * @method static int increment(string $key, int $value = 1)
  14. *
  15. * @see \App\Services\RedisCache
  16. */
  17. class RedisCache extends Facade
  18. {
  19. /**
  20. * 换成内存实现,测试用。
  21. */
  22. public static function fake(): RedisCacheFake
  23. {
  24. static::swap($fake = new RedisCacheFake);
  25. return $fake;
  26. }
  27. protected static function getFacadeAccessor(): string
  28. {
  29. return \App\Services\RedisCache::class;
  30. }
  31. }