usercache.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Cache;
  9. /**
  10. * This interface defines method for accessing the file based user cache.
  11. */
  12. class UserCache implements \OCP\ICache {
  13. /**
  14. * @var \OC\Cache\File $userCache
  15. */
  16. protected $userCache;
  17. public function __construct() {
  18. $this->userCache = new File();
  19. }
  20. /**
  21. * Get a value from the user cache
  22. *
  23. * @param string $key
  24. * @return mixed
  25. */
  26. public function get($key) {
  27. return $this->userCache->get($key);
  28. }
  29. /**
  30. * Set a value in the user cache
  31. *
  32. * @param string $key
  33. * @param mixed $value
  34. * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
  35. * @return bool
  36. */
  37. public function set($key, $value, $ttl = 0) {
  38. if (empty($key)) {
  39. return false;
  40. }
  41. return $this->userCache->set($key, $value, $ttl);
  42. }
  43. /**
  44. * Check if a value is set in the user cache
  45. *
  46. * @param string $key
  47. * @return bool
  48. */
  49. public function hasKey($key) {
  50. return $this->userCache->hasKey($key);
  51. }
  52. /**
  53. * Remove an item from the user cache
  54. *
  55. * @param string $key
  56. * @return bool
  57. */
  58. public function remove($key) {
  59. return $this->userCache->remove($key);
  60. }
  61. /**
  62. * clear the user cache of all entries starting with a prefix
  63. * @param string $prefix (optional)
  64. * @return bool
  65. */
  66. public function clear($prefix = '') {
  67. return $this->userCache->clear($prefix);
  68. }
  69. }