apc.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  10. * entries in APC gets namespaced to prevent collisions between owncloud instances and users
  11. */
  12. protected function getNameSpace() {
  13. return OC_Util::getInstanceId().'/'.OC_User::getUser().'/';
  14. }
  15. public function get($key) {
  16. $result = apc_fetch($this->getNamespace().$key, $success);
  17. if (!$success) {
  18. return null;
  19. }
  20. return $result;
  21. }
  22. public function set($key, $value, $ttl=0) {
  23. return apc_store($this->getNamespace().$key, $value, $ttl);
  24. }
  25. public function hasKey($key) {
  26. return apc_exists($this->getNamespace().$key);
  27. }
  28. public function remove($key) {
  29. return apc_delete($this->getNamespace().$key);
  30. }
  31. public function clear(){
  32. $ns = $this->getNamespace();
  33. $cache = apc_cache_info('user');
  34. foreach($cache['cache_list'] as $entry) {
  35. if (strpos($entry['info'], $ns) === 0) {
  36. apc_delete($entry['info']);
  37. }
  38. }
  39. }
  40. }