usercache.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. * @author Thomas Tanghus <thomas@tanghus.net>
  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\Cache;
  25. /**
  26. * This interface defines method for accessing the file based user cache.
  27. */
  28. class UserCache implements \OCP\ICache {
  29. /**
  30. * @var \OC\Cache\File $userCache
  31. */
  32. protected $userCache;
  33. public function __construct() {
  34. $this->userCache = new File();
  35. }
  36. /**
  37. * Get a value from the user cache
  38. *
  39. * @param string $key
  40. * @return mixed
  41. */
  42. public function get($key) {
  43. return $this->userCache->get($key);
  44. }
  45. /**
  46. * Set a value in the user cache
  47. *
  48. * @param string $key
  49. * @param string $value
  50. * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
  51. * @return bool
  52. */
  53. public function set($key, $value, $ttl = 0) {
  54. if (empty($key)) {
  55. return false;
  56. }
  57. return $this->userCache->set($key, $value, $ttl);
  58. }
  59. /**
  60. * Check if a value is set in the user cache
  61. *
  62. * @param string $key
  63. * @return bool
  64. */
  65. public function hasKey($key) {
  66. return $this->userCache->hasKey($key);
  67. }
  68. /**
  69. * Remove an item from the user cache
  70. *
  71. * @param string $key
  72. * @return bool
  73. */
  74. public function remove($key) {
  75. return $this->userCache->remove($key);
  76. }
  77. /**
  78. * clear the user cache of all entries starting with a prefix
  79. * @param string $prefix (optional)
  80. * @return bool
  81. */
  82. public function clear($prefix = '') {
  83. return $this->userCache->clear($prefix);
  84. }
  85. }