Cache.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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;
  12. use Hyperf\Cache\Driver\DriverInterface;
  13. use Psr\SimpleCache\CacheInterface;
  14. class Cache implements CacheInterface
  15. {
  16. protected DriverInterface $driver;
  17. public function __construct(CacheManager $manager)
  18. {
  19. $this->driver = $manager->getDriver();
  20. }
  21. public function __call($name, $arguments)
  22. {
  23. return $this->driver->{$name}(...$arguments);
  24. }
  25. public function get($key, $default = null): mixed
  26. {
  27. return $this->__call(__FUNCTION__, func_get_args());
  28. }
  29. public function set($key, $value, $ttl = null): bool
  30. {
  31. return $this->__call(__FUNCTION__, func_get_args());
  32. }
  33. public function delete($key): bool
  34. {
  35. return $this->__call(__FUNCTION__, func_get_args());
  36. }
  37. public function clear(): bool
  38. {
  39. return $this->__call(__FUNCTION__, func_get_args());
  40. }
  41. public function getMultiple($keys, $default = null): iterable
  42. {
  43. return $this->__call(__FUNCTION__, func_get_args());
  44. }
  45. public function setMultiple($values, $ttl = null): bool
  46. {
  47. return $this->__call(__FUNCTION__, func_get_args());
  48. }
  49. public function deleteMultiple($keys): bool
  50. {
  51. return $this->__call(__FUNCTION__, func_get_args());
  52. }
  53. public function has($key): bool
  54. {
  55. return $this->__call(__FUNCTION__, func_get_args());
  56. }
  57. }