cache.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 $cache;
  10. static protected function init() {
  11. $fast_cache = null;
  12. if (!$fast_cache && function_exists('xcache_set')) {
  13. $fast_cache = new OC_Cache_XCache();
  14. }
  15. if (!$fast_cache && function_exists('apc_store')) {
  16. $fast_cache = new OC_Cache_APC();
  17. }
  18. self::$cache = new OC_Cache_File();
  19. if ($fast_cache) {
  20. self::$cache = new OC_Cache_Broker($fast_cache, self::$cache);
  21. }
  22. }
  23. static public function get($key) {
  24. if (!self::$cache) {
  25. self::init();
  26. }
  27. return self::$cache->get($key);
  28. }
  29. static public function set($key, $value, $ttl=0) {
  30. if (empty($key)) {
  31. return false;
  32. }
  33. if (!self::$cache) {
  34. self::init();
  35. }
  36. return self::$cache->set($key, $value, $ttl);
  37. }
  38. static public function hasKey($key) {
  39. if (!self::$cache) {
  40. self::init();
  41. }
  42. return self::$cache->hasKey($key);
  43. }
  44. static public function remove($key) {
  45. if (!self::$cache) {
  46. self::init();
  47. }
  48. return self::$cache->remove($key);
  49. }
  50. static public function clear() {
  51. if (!self::$cache) {
  52. self::init();
  53. }
  54. return self::$cache->clear();
  55. }
  56. }