summaryrefslogtreecommitdiff
path: root/framework/I18N/core/TCache_Lite.php
diff options
context:
space:
mode:
authorxue <>2006-04-30 12:51:23 +0000
committerxue <>2006-04-30 12:51:23 +0000
commitddfafaac2c1f18aca0fda3b4157acd935b9ac9a2 (patch)
treed131537413fa80aadf44feb8607eca6584e539f7 /framework/I18N/core/TCache_Lite.php
parent10b65d6d03ee0afc1ec1a50f320af42a79f5492b (diff)
merge from 3.0 branch till 995.
Diffstat (limited to 'framework/I18N/core/TCache_Lite.php')
-rw-r--r--framework/I18N/core/TCache_Lite.php91
1 files changed, 47 insertions, 44 deletions
diff --git a/framework/I18N/core/TCache_Lite.php b/framework/I18N/core/TCache_Lite.php
index 078b0fe2..b42afc10 100644
--- a/framework/I18N/core/TCache_Lite.php
+++ b/framework/I18N/core/TCache_Lite.php
@@ -16,7 +16,7 @@
* @version $Revision: 1.3 $ $Date: 2005/10/09 10:24:12 $
* @package System.I18N.core
*/
-
+
/**
* Fast, light and safe Cache Class
*
@@ -40,6 +40,9 @@
* @package System.I18N.core
* @version $Id: TCache_Lite.php,v 1.3 2005/10/09 10:24:12 weizhuo Exp $
* @author Fabien MARTY <fab@php.net>
+* @copyright 1997-2005 The PHP Group
+* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
+* @link http://pear.php.net/package/Cache_Lite
*/
class TCache_Lite
{
@@ -94,11 +97,11 @@ class TCache_Lite
protected $_file;
/**
- * Enable / disable write control (the cache is read just after writing
+ * Enable / disable write control (the cache is read just after writing
* to detect corrupt entries)
*
- * Enable write control will lightly slow the cache writing but not the
- * cache reading. Write control can detect some corrupt cache files but
+ * Enable write control will lightly slow the cache writing but not the
+ * cache reading. Write control can detect some corrupt cache files but
* maybe it's not a perfect control
*
* @var boolean $_writeControl
@@ -108,7 +111,7 @@ class TCache_Lite
/**
* Enable / disable read control
*
- * If enabled, a control key is embeded in cache file and this key is
+ * If enabled, a control key is embeded in cache file and this key is
* compared with the one calculated after the reading.
*
* @var boolean $_writeControl
@@ -120,7 +123,7 @@ class TCache_Lite
*
* Available values are :
* 'md5' for a md5 hash control (best but slowest)
- * 'crc32' for a crc32 hash control (lightly less safe but faster,
+ * 'crc32' for a crc32 hash control (lightly less safe but faster,
* better choice)
* 'strlen' for a length only test (fastest)
*
@@ -145,7 +148,7 @@ class TCache_Lite
/**
* Enable / Disable "Memory Caching"
*
- * NB : There is no lifetime for memory caching !
+ * NB : There is no lifetime for memory caching !
*
* @var boolean $_memoryCaching
*/
@@ -179,7 +182,7 @@ class TCache_Lite
* @var int $memoryCachingLimit
*/
protected $_memoryCachingLimit = 1000;
-
+
/**
* File Name protection
*
@@ -191,17 +194,17 @@ class TCache_Lite
* @var boolean $fileNameProtection
*/
protected $_fileNameProtection = true;
-
+
/**
* Enable / disable automatic serialization
*
* it can be used to save directly datas which aren't strings
- * (but it's slower)
+ * (but it's slower)
*
* @var boolean $_serialize
*/
protected $_automaticSerialization = false;
-
+
// --- Public methods ---
/**
@@ -228,17 +231,17 @@ class TCache_Lite
*/
function TCache_Lite($options = array(null))
{
- $availableOptions = array( 'automaticSerialization',
- 'fileNameProtection',
- 'memoryCaching',
- 'onlyMemoryCaching',
- 'memoryCachingLimit',
- 'cacheDir',
- 'caching',
- 'lifeTime',
- 'fileLocking',
- 'writeControl',
- 'readControl',
+ $availableOptions = array( 'automaticSerialization',
+ 'fileNameProtection',
+ 'memoryCaching',
+ 'onlyMemoryCaching',
+ 'memoryCachingLimit',
+ 'cacheDir',
+ 'caching',
+ 'lifeTime',
+ 'fileLocking',
+ 'writeControl',
+ 'readControl',
'readControlType');
foreach($options as $key => $value) {
if(in_array($key, $availableOptions)) {
@@ -248,7 +251,7 @@ class TCache_Lite
}
$this->_refreshTime = time() - $this->_lifeTime;
}
-
+
/**
* Test if a cache is available and (if yes) return it
*
@@ -299,11 +302,11 @@ class TCache_Lite
}
return false;
}
-
+
/**
* Save some data in a cache file
*
- * @param string $data data to put in cache (can be another type than strings
+ * @param string $data data to put in cache (can be another type than strings
* if automaticSerialization is on)
* @param string $id cache id
* @param string $group name of the cache group
@@ -351,7 +354,7 @@ class TCache_Lite
{
$this->_setFileName($id, $group);
if (!@unlink($this->_file)) {
- $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
+ $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
return false;
}
return true;
@@ -367,7 +370,7 @@ class TCache_Lite
* @return boolean true if no problem
* @access public
*/
- function clean($group = false)
+ function clean($group = false)
{
if ($this->_fileNameProtection) {
$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
@@ -378,7 +381,7 @@ class TCache_Lite
while (list($key, $value) = each($this->_memoryCaching)) {
if (strpos($key, $motif, 0)) {
unset($this->_memoryCaching[$key]);
- $this->_memoryCachingCounter =
+ $this->_memoryCachingCounter =
$this->_memoryCachingCounter - 1;
}
}
@@ -405,7 +408,7 @@ class TCache_Lite
}
return true;
}
-
+
/**
* Set a new life time
*
@@ -438,11 +441,11 @@ class TCache_Lite
*
* @access public
*/
- function getMemoryCachingState($id, $group = 'default',
+ function getMemoryCachingState($id, $group = 'default',
$doNotTestCacheValidity = false)
{
if ($this->_caching) {
- if ($data = $this->get($id, $group, $doNotTestCacheValidity))
+ if ($data = $this->get($id, $group, $doNotTestCacheValidity))
{
$array = unserialize($data);
$this->_memoryCachingCounter = $array['counter'];
@@ -450,7 +453,7 @@ class TCache_Lite
}
}
}
-
+
/**
* Return the cache last modification time
*
@@ -461,7 +464,7 @@ class TCache_Lite
function lastModified() {
return filemtime($this->cache->_file);
}
-
+
/**
* Trigger a PEAR error
*
@@ -511,12 +514,12 @@ class TCache_Lite
$this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
}
}
-
+
function getCacheFile()
{
return $this->_file;
}
-
+
/**
* Read the cache file and return the content
*
@@ -529,14 +532,14 @@ class TCache_Lite
if ($this->_fileLocking) @flock($fp, LOCK_SH);
if ($fp) {
// because the filesize can be cached by PHP itself...
- clearstatcache();
+ clearstatcache();
$length = @filesize($this->_file);
$mqr = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
if ($this->_readControl) {
$hashControl = @fread($fp, 32);
$length = $length - 32;
- }
+ }
$data = @fread($fp, $length);
set_magic_quotes_runtime($mqr);
if ($this->_fileLocking) @flock($fp, LOCK_UN);
@@ -544,16 +547,16 @@ class TCache_Lite
if ($this->_readControl) {
$hashData = $this->_hash($data, $this->_readControlType);
if ($hashData != $hashControl) {
- @touch($this->_file, time() - 2*abs($this->_lifeTime));
+ @touch($this->_file, time() - 2*abs($this->_lifeTime));
return false;
}
}
return $data;
}
- $this->raiseError('Cache_Lite : Unable to read cache !', -2);
+ $this->raiseError('Cache_Lite : Unable to read cache !', -2);
return false;
}
-
+
/**
* Write the given data in the cache file
*
@@ -578,7 +581,7 @@ class TCache_Lite
$this->raiseError('Cache_Lite : Unable to write cache !', -1);
return false;
}
-
+
/**
* Write the given data in the cache file and control it just after to avoid
* corrupted cache entries
@@ -593,7 +596,7 @@ class TCache_Lite
$dataRead = $this->_read($data);
return ($dataRead==$data);
}
-
+
/**
* Make a control key with the string containing datas
*
@@ -616,7 +619,7 @@ class TCache_Lite
'(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
}
}
-
-}
+
+}
?>