CacheEngineInterface.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.7.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Cache;
  17. /**
  18. * Interface for cache engines that defines methods
  19. * outside of the PSR16 interface that are used by `Cache`.
  20. *
  21. * Internally Cache uses this interface when calling engine
  22. * methods.
  23. *
  24. * @since 3.7.0
  25. */
  26. interface CacheEngineInterface
  27. {
  28. /**
  29. * Write data for key into a cache engine if it doesn't exist already.
  30. *
  31. * @param string $key Identifier for the data.
  32. * @param mixed $value Data to be cached - anything except a resource.
  33. * @return bool True if the data was successfully cached, false on failure.
  34. * Or if the key existed already.
  35. */
  36. public function add(string $key, $value): bool;
  37. /**
  38. * Increment a number under the key and return incremented value
  39. *
  40. * @param string $key Identifier for the data
  41. * @param int $offset How much to add
  42. * @return int|false New incremented value, false otherwise
  43. */
  44. public function increment(string $key, int $offset = 1);
  45. /**
  46. * Decrement a number under the key and return decremented value
  47. *
  48. * @param string $key Identifier for the data
  49. * @param int $offset How much to subtract
  50. * @return int|false New incremented value, false otherwise
  51. */
  52. public function decrement(string $key, int $offset = 1);
  53. /**
  54. * Clear all values belonging to the named group.
  55. *
  56. * Each implementation needs to decide whether actually
  57. * delete the keys or just augment a group generation value
  58. * to achieve the same result.
  59. *
  60. * @param string $group name of the group to be cleared
  61. * @return bool
  62. */
  63. public function clearGroup(string $group): bool;
  64. }