cvs: pear /Cache_Lite/Lite Function.php
| From: | Fabien MARTY | Date: | Thu, 17 Nov 2005 09:19:21 +0000 |
| Subject: | cvs: pear /Cache_Lite/Lite Function.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36342@lists.php.net to get a copy of this message | ||
fab Thu Nov 17 04:19:21 2005 EDT
Modified files:
/pear/Cache_Lite/Lite Function.php
Log:
Add a way to drop Cache_Lite_Function individual cache files (thanks to Hugo Morganho <hjm (at)
holos (dot) pt>)
http://cvs.php.net/diff.php/pear/Cache_Lite/Lite/Function.php?r1=1.6&r2=1.7&ty=u
Index: pear/Cache_Lite/Lite/Function.php
diff -u pear/Cache_Lite/Lite/Function.php:1.6 pear/Cache_Lite/Lite/Function.php:1.7
--- pear/Cache_Lite/Lite/Function.php:1.6 Tue Feb 3 12:07:13 2004
+++ pear/Cache_Lite/Lite/Function.php Thu Nov 17 04:19:18 2005
@@ -11,7 +11,7 @@
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
-* @version $Id: Function.php,v 1.6 2004/02/03 17:07:13 fab Exp $
+* @version $Id: Function.php,v 1.7 2005/11/17 09:19:18 fab Exp $
* @author Sebastian BERGMANN <sb@sebastian-bergmann.de>
* @author Fabien MARTY <fab@php.net>
*/
@@ -69,12 +69,7 @@
function call()
{
$arguments = func_get_args();
- $id = serialize($arguments); // Generate a cache id
- if (!$this->_fileNameProtection) {
- $id = md5($id);
- // if fileNameProtection is set to false, then the id has to be hashed
- // because it's a very bad file name in most cases
- }
+ $id = $this->_makeId($arguments);
$data = $this->get($id, $this->_defaultGroup);
if ($data !== false) {
$array = unserialize($data);
@@ -88,7 +83,7 @@
list($class, $method) = explode('::', $target);
$result = call_user_func_array(array($class, $method), $arguments);
} else if (strstr($target, '->')) { // object->method
- // use a stupid name ($objet_123456789 because) of problems when the object
+ // use a stupid name ($objet_123456789 because) of problems whene the object
// name is the same as this var name
list($object_123456789, $method) = explode('->', $target);
global $$object_123456789;
@@ -106,6 +101,40 @@
return $result;
}
+ /**
+ * Drop a cache file
+ *
+ * Arguments of this method are read with func_get_args. So it doesn't appear
+ * in the function definition. Synopsis :
+ * remove('functionName', $arg1, $arg2, ...)
+ * (arg1, arg2... are arguments of 'functionName')
+ *
+ * @return boolean true if no problem
+ * @access public
+ */
+ function drop()
+ {
+ $id = $this->_makeId(func_get_args());
+ $this->remove($id, $this->_defaultGroup);
+ }
+
+ /**
+ * Make an id for the cache
+ *
+ * @var array result of func_get_args for the call() or the remove() method
+ * @return string id
+ * @access private
+ */
+ function _makeId($arguments) {
+ $id = serialize($arguments); // Generate a cache id
+ if (!$this->_fileNameProtection) {
+ $id = md5($id);
+ // if fileNameProtection is set to false, then the id has to be hashed
+ // because it's a very bad file name in most cases
+ }
+ return $id;
+ }
+
}
?>