You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

  1. <?php
  2. /**
  3. * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class OC_Cache {
  9. static protected $user_cache;
  10. static protected $global_cache;
  11. static public function getGlobalCache() {
  12. if (!self::$global_cache) {
  13. $fast_cache = null;
  14. if (!$fast_cache && function_exists('xcache_set')) {
  15. $fast_cache = new OC_Cache_XCache(true);
  16. }
  17. if (!$fast_cache && function_exists('apc_store')) {
  18. $fast_cache = new OC_Cache_APC(true);
  19. }
  20. self::$global_cache = new OC_Cache_FileGlobal();
  21. if ($fast_cache) {
  22. self::$global_cache = new OC_Cache_Broker($fast_cache, self::$global_cache);
  23. }
  24. }
  25. return self::$global_cache;
  26. }
  27. static public function getUserCache() {
  28. if (!self::$user_cache) {
  29. $fast_cache = null;
  30. if (!$fast_cache && function_exists('xcache_set')) {
  31. $fast_cache = new OC_Cache_XCache();
  32. }
  33. if (!$fast_cache && function_exists('apc_store')) {
  34. $fast_cache = new OC_Cache_APC();
  35. }
  36. self::$user_cache = new OC_Cache_File();
  37. if ($fast_cache) {
  38. self::$user_cache = new OC_Cache_Broker($fast_cache, self::$user_cache);
  39. }
  40. }
  41. return self::$user_cache;
  42. }
  43. static public function get($key) {
  44. $user_cache = self::getUserCache();
  45. return $user_cache->get($key);
  46. }
  47. static public function set($key, $value, $ttl=0) {
  48. if (empty($key)) {
  49. return false;
  50. }
  51. $user_cache = self::getUserCache();
  52. return $user_cache->set($key, $value, $ttl);
  53. }
  54. static public function hasKey($key) {
  55. $user_cache = self::getUserCache();
  56. return $user_cache->hasKey($key);
  57. }
  58. static public function remove($key) {
  59. $user_cache = self::getUserCache();
  60. return $user_cache->remove($key);
  61. }
  62. static public function clear() {
  63. $user_cache = self::getUserCache();
  64. return $user_cache->clear();
  65. }
  66. }