cache.php 2.1 KB

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