apc.php 1.4 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_APC {
  9. protected $prefix;
  10. public function __construct($global = false) {
  11. $this->prefix = OC_Util::getInstanceId().'/';
  12. if (!$global) {
  13. $this->prefix .= OC_User::getUser().'/';
  14. }
  15. }
  16. /**
  17. * entries in APC gets namespaced to prevent collisions between owncloud instances and users
  18. */
  19. protected function getNameSpace() {
  20. return $this->prefix;
  21. }
  22. public function get($key) {
  23. $result = apc_fetch($this->getNamespace().$key, $success);
  24. if (!$success) {
  25. return null;
  26. }
  27. return $result;
  28. }
  29. public function set($key, $value, $ttl=0) {
  30. return apc_store($this->getNamespace().$key, $value, $ttl);
  31. }
  32. public function hasKey($key) {
  33. return apc_exists($this->getNamespace().$key);
  34. }
  35. public function remove($key) {
  36. return apc_delete($this->getNamespace().$key);
  37. }
  38. public function clear($prefix='') {
  39. $ns = $this->getNamespace().$prefix;
  40. $cache = apc_cache_info('user');
  41. foreach($cache['cache_list'] as $entry) {
  42. if (strpos($entry['info'], $ns) === 0) {
  43. apc_delete($entry['info']);
  44. }
  45. }
  46. return true;
  47. }
  48. }
  49. if(!function_exists('apc_exists')) {
  50. function apc_exists($keys)
  51. {
  52. $result;
  53. apc_fetch($keys, $result);
  54. return $result;
  55. }
  56. }