mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Merging fixes and enhancements into trunk.
Revision: [2257] Refactored cache code in view class. Removed adding the timestamp to the file contents, it is now added to the file name Revision: [2256] Refactored cache checking code. Time stamp is not added to file name so we check this instead of reading the file and finding timestamp Revision: [2255] Adding clearCache function to delete contents of cache git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2258 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
265386fc2a
commit
7c8df25770
4 changed files with 108 additions and 23 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
1.0.0.2254
|
||||
1.0.0.2258
|
|
@ -897,6 +897,81 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache')
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to delete files in the cache directories, or clear contents of cache directories
|
||||
*
|
||||
* @param mixed $params As String name to be searched for deletion, if name is a directory all files in directory will be deleted.
|
||||
* If array, names to be searched for deletion.
|
||||
* If clearCache() without params, all files in app/tmp/cache/views will be deleted
|
||||
*
|
||||
* @param string $type Directory in tmp/cache defaults to view directory
|
||||
* @param string $ext The file extension you are deleting
|
||||
* @return true if files found and deleted false otherwise
|
||||
*/
|
||||
function clearCache($params = null, $type = 'views', $ext = '.php')
|
||||
{
|
||||
if(is_string($params) || $params === null)
|
||||
{
|
||||
$cache = CACHE.$type.DS.$params;
|
||||
if(is_file($cache.$ext))
|
||||
{
|
||||
return unlink($cache);
|
||||
}
|
||||
else if(is_dir($cache))
|
||||
{
|
||||
$files = glob("$cache*");
|
||||
if ($files === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
array_map('unlink', $files);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache = CACHE.$type.DS.'*'.$params.'*'.$ext;
|
||||
$files = glob($cache);
|
||||
if ($files === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
array_map('unlink', $files);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(is_array($params))
|
||||
{
|
||||
foreach ($params as $key => $file)
|
||||
{
|
||||
$cache = CACHE.$type.DS.'*'.$file.'*'.$ext;
|
||||
$files[] = glob($cache);
|
||||
}
|
||||
if(!empty($files))
|
||||
{
|
||||
foreach ($files as $key => $delete)
|
||||
{
|
||||
array_map('unlink', $delete);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $value
|
||||
* @return unknown
|
||||
*/
|
||||
function stripslashes_deep($value)
|
||||
{
|
||||
$value = is_array($value) ?
|
||||
|
@ -959,6 +1034,12 @@ function LogError ($message)
|
|||
CakeLog::write('error', str_replace($bad, $good, $message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches include path for files
|
||||
*
|
||||
* @param string $file
|
||||
* @return Full path to file if exists, otherwise false
|
||||
*/
|
||||
function fileExistsInPath ($file)
|
||||
{
|
||||
$paths = explode(PATH_SEPARATOR, get_include_path());
|
||||
|
|
|
@ -114,27 +114,31 @@ if(defined('CACHE_CHECK') && CACHE_CHECK === true)
|
|||
$uri = setUri();
|
||||
}
|
||||
|
||||
$filename = CACHE.'views'.DS.str_replace('/', '_', $uri.'.php');
|
||||
$filename = CACHE.'views'.DS.'*'.str_replace('/', '_', $uri).'*';
|
||||
$files = glob($filename);
|
||||
|
||||
if (file_exists($filename))
|
||||
if(isset($files[0]))
|
||||
{
|
||||
ob_start();
|
||||
include($filename);
|
||||
if (DEBUG)
|
||||
if (file_exists($files[0]))
|
||||
{
|
||||
echo "<!-- Cached Render Time: ". round(getMicrotime() - $TIME_START, 4) ."s -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match))
|
||||
{
|
||||
if(time() >= $match['1'])
|
||||
if (preg_match('/(\\d+).php/', $files[0], $match))
|
||||
{
|
||||
@unlink($filename);
|
||||
unset($out);
|
||||
}
|
||||
else
|
||||
{
|
||||
die(e($out));
|
||||
if(time() >= $match['1'])
|
||||
{
|
||||
@unlink($files[0]);
|
||||
unset($out);
|
||||
}
|
||||
else
|
||||
{
|
||||
ob_start();
|
||||
include($files[0]);
|
||||
if (DEBUG)
|
||||
{
|
||||
echo "<!-- Cached Render Time: ". round(getMicrotime() - $TIME_START, 4) ."s -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
die(e($out));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -802,16 +802,16 @@ class View extends Object
|
|||
$now = time();
|
||||
if (is_numeric($timestamp))
|
||||
{
|
||||
$timestamp = $now + $timestamp;
|
||||
$cacheTime = $now + $timestamp;
|
||||
}
|
||||
else
|
||||
{
|
||||
$timestamp = $now + strtotime($timestamp);
|
||||
$cacheTime = $now + strtotime($timestamp);
|
||||
}
|
||||
$content = '<!--cachetime:' . $timestamp . '-->'.$view;
|
||||
$result = preg_replace('/\/\//', '/', $this->here);
|
||||
$cache = str_replace('/', '_', $result.'.php');
|
||||
return cache('views'.DS.$cache, $content, $timestamp);
|
||||
$cache = str_replace('/', '_', $result.$cacheTime.'.php');
|
||||
$cache = str_replace('favicon.ico', '', $cache);
|
||||
return cache('views'.DS.$cache, $view, $timestamp);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue