From fc56a668ce756811f8b98557548fff2bf34799a4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 5 Jun 2012 23:19:28 +0200 Subject: Add OC_Cache implementation for APC --- lib/cache/apc.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/cache/apc.php (limited to 'lib/cache') diff --git a/lib/cache/apc.php b/lib/cache/apc.php new file mode 100644 index 00000000000..f814afbe494 --- /dev/null +++ b/lib/cache/apc.php @@ -0,0 +1,46 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Cache_APC { + /** + * entries in APC gets namespaced to prevent collisions between owncloud instances and users + */ + protected function getNameSpace() { + return OC_Util::getInstanceId().'/'.OC_User::getUser().'/'; + } + + public function get($key) { + $result = apc_fetch($this->getNamespace().$key, $success); + if (!$success) { + return null; + } + return $result; + } + + public function set($key, $value, $ttl=0) { + return apc_store($this->getNamespace().$key, $value, $ttl); + } + + public function hasKey($key) { + return apc_exists($this->getNamespace().$key); + } + + public function remove($key) { + return apc_delete($this->getNamespace().$key); + } + + public function clear(){ + $ns = $this->getNamespace(); + $cache = apc_cache_info('user'); + foreach($cache['cache_list'] as $entry) { + if (strpos($entry['info'], $ns) === 0) { + apc_delete($entry['info']); + } + } + } +} -- cgit v1.2.3