factory.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  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\Memcache;
  9. class Factory {
  10. /**
  11. * get a cache instance, will return null if no backend is available
  12. *
  13. * @param string $prefix
  14. * @return \OC\Memcache\Cache
  15. */
  16. function create($prefix = '') {
  17. if (XCache::isAvailable()) {
  18. return new XCache($prefix);
  19. } elseif (APCu::isAvailable()) {
  20. return new APCu($prefix);
  21. } elseif (APC::isAvailable()) {
  22. return new APC($prefix);
  23. } elseif (Memcached::isAvailable()) {
  24. return new Memcached($prefix);
  25. } else {
  26. return null;
  27. }
  28. }
  29. /**
  30. * check if there is a memcache backend available
  31. *
  32. * @return bool
  33. */
  34. public function isAvailable() {
  35. return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
  36. }
  37. /**
  38. * get a in-server cache instance, will return null if no backend is available
  39. *
  40. * @param string $prefix
  41. * @return \OC\Memcache\Cache
  42. */
  43. public static function createLowLatency($prefix = '') {
  44. if (XCache::isAvailable()) {
  45. return new XCache($prefix);
  46. } elseif (APCu::isAvailable()) {
  47. return new APCu($prefix);
  48. } elseif (APC::isAvailable()) {
  49. return new APC($prefix);
  50. } else {
  51. return null;
  52. }
  53. }
  54. /**
  55. * check if there is a in-server backend available
  56. *
  57. * @return bool
  58. */
  59. public static function isAvailableLowLatency() {
  60. return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable();
  61. }
  62. }