Skip to content

Commit

Permalink
Optimized the changes to Kohana::cache() in 83d287d
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Aug 3, 2009
1 parent 83d287d commit db40e56
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions classes/kohana/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public static function config($group)
public static function cache($name, $data = NULL, $lifetime = 60)
{
// Cache file is a hash of the name
$file = sha1($name).EXT;
$file = sha1($name).'.txt';

// Cache directories are split by keys to prevent filesystem overload
$dir = self::$cache_dir."/{$file[0]}{$file[1]}/";
Expand All @@ -697,7 +697,7 @@ public static function cache($name, $data = NULL, $lifetime = 60)
if ((time() - filemtime($dir.$file)) < $lifetime)
{
// Return the cache
return unserialize(include $dir.$file);
return unserialize(file_get_contents($dir.$file));
}
else
{
Expand All @@ -720,12 +720,7 @@ public static function cache($name, $data = NULL, $lifetime = 60)
}

// Write the cache
return (bool) file_put_contents($dir.$file, strtr(self::FILE_CACHE, array
(
':header' => self::FILE_SECURITY,
':name' => $name,
':data' => 'return '.var_export(serialize($data), TRUE).';',
)));
return (bool) file_put_contents($dir.$file, serialize($data));
}
catch (Exception $e)
{
Expand Down

0 comments on commit db40e56

Please sign in to comment.