diff --git a/phpgwapi/inc/class.egw_cache_apc.inc.php b/phpgwapi/inc/class.egw_cache_apc.inc.php index 6cc83c0645..5c13d09f28 100644 --- a/phpgwapi/inc/class.egw_cache_apc.inc.php +++ b/phpgwapi/inc/class.egw_cache_apc.inc.php @@ -116,13 +116,30 @@ class egw_cache_apc extends egw_cache_provider_check implements egw_cache_provid return apc_delete(self::key($keys)); } + /** + * Delete all data under given keys + * + * @param array $keys eg. array($level,$app,$location) + * @return boolean true on success, false on error (eg. $key not set) + */ + function flush(array $keys) + { + //error_log(__METHOD__."(".array2string($keys).")"); + foreach(new APCIterator('user', $preg='/^'.preg_quote(self::key($keys).'/')) as $item) + { + //error_log(__METHOD__."(".array2string($keys).") preg='$preg': calling apc_delete('$item[key]')"); + apc_delete($item['key']); + } + return true; + } + /** * Create a single key from $keys * * @param array $keys * @return string */ - private function key(array $keys) + private static function key(array $keys) { return implode('::',$keys); } diff --git a/phpgwapi/inc/class.egw_cache_files.inc.php b/phpgwapi/inc/class.egw_cache_files.inc.php index 78441d1663..7a49a8a66d 100644 --- a/phpgwapi/inc/class.egw_cache_files.inc.php +++ b/phpgwapi/inc/class.egw_cache_files.inc.php @@ -114,6 +114,49 @@ class egw_cache_files extends egw_cache_provider_check implements egw_cache_prov return unlink($fname); } + /** + * Delete all data under given keys + * + * @param array $keys eg. array($level,$app,$location) + * @return boolean true on success, false on error (eg. $key not set) + */ + function flush(array $keys) + { + $dir = $this->filename($keys, false); + + return file_exists($dir) ? self::rm_recursive($dir) : true; + } + + /** + * Recursive delete a path + * + * @param string $path + * @return boolean true on success, false otherwise + */ + private static function rm_recursive($path) + { + if (!is_dir($path)) + { + return unlink($path); + } + foreach(scandir($path) as $file) + { + if ($file == '.' || $file == '..') continue; + + $file = $path.'/'.$file; + + if (is_dir($file)) + { + if (!self::rm_recursive($file)) return false; + } + else + { + if (!unlink($path.'/'.$file)) return false; + } + } + return rmdir($path); + } + /** * Create a path from $keys and $basepath *