Cache.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Robin McCorkell <robin@mccorkell.me.uk>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Memcache;
  26. abstract class Cache implements \ArrayAccess, \OCP\ICache {
  27. /**
  28. * @var string $prefix
  29. */
  30. protected $prefix;
  31. /**
  32. * @param string $prefix
  33. */
  34. public function __construct($prefix = '') {
  35. $this->prefix = $prefix;
  36. }
  37. /**
  38. * @return string Prefix used for caching purposes
  39. */
  40. public function getPrefix() {
  41. return $this->prefix;
  42. }
  43. /**
  44. * @param string $key
  45. * @return mixed
  46. */
  47. abstract public function get($key);
  48. /**
  49. * @param string $key
  50. * @param mixed $value
  51. * @param int $ttl
  52. * @return mixed
  53. */
  54. abstract public function set($key, $value, $ttl = 0);
  55. /**
  56. * @param string $key
  57. * @return mixed
  58. */
  59. abstract public function hasKey($key);
  60. /**
  61. * @param string $key
  62. * @return mixed
  63. */
  64. abstract public function remove($key);
  65. /**
  66. * @param string $prefix
  67. * @return mixed
  68. */
  69. abstract public function clear($prefix = '');
  70. //implement the ArrayAccess interface
  71. public function offsetExists($offset) {
  72. return $this->hasKey($offset);
  73. }
  74. public function offsetSet($offset, $value) {
  75. $this->set($offset, $value);
  76. }
  77. public function offsetGet($offset) {
  78. return $this->get($offset);
  79. }
  80. public function offsetUnset($offset) {
  81. $this->remove($offset);
  82. }
  83. }