1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/manual/new/lib/Cache.php
jepso 9b61957154 - New feature in documentation: you can now link to other documentation sections with the following syntax:
- [doc getting-started:installation], or
    - [doc getting-started:installation Custom link text]
- Updated Text_Wiki to 1.2.0
- Documentation should now pass XHTML validator
- Formatted DSN section so that it's easier on eyes
- The single quotes in <code type='php'> won't work anymore due to the Text_Wiki update. Use double quotes instead: <code type="php">. The single quotes have been converted to double quotes in documentation files.
- Modified the links in h1-h6 headings to use the same style as the headings.
- Some refactoring
2007-07-20 08:03:04 +00:00

81 lines
1.9 KiB
PHP

<?php
class Cache
{
protected $_dir;
protected $_ext;
protected $_page;
protected $_file;
public function __construct($dir, $ext)
{
$this->_dir = $dir;
$this->_ext = $ext;
$this->_page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$this->_file = $this->_dir . md5($this->_page) . '.' . $this->_ext;
}
/**
* Begins caching the output.
*
* @return A boolean value indicating whether a valid cached version of the
* page was found and echoed (false), or not (true).
*/
public function begin()
{
$showCache = (file_exists($this->_file) && $this->isValid());
clearstatcache();
if ($showCache) {
readfile($this->_file);
return false;
} else {
ob_start();
return true;
}
}
/**
* Ends caching the output and saves it to a cache file.
*
*/
public function end()
{
// Generate a new cache file
$fp = @fopen($this->_file, 'w');
// Save the contents of output buffer to the file
@fwrite($fp, ob_get_contents());
@fclose($fp);
ob_end_flush();
}
/**
* Deletes all files in the cache directory.
*/
public function clear()
{
if ($handle = @opendir($this->_dir)) {
while ($file = readdir($handle)) {
if ($file !== '.' && $file !== '..') {
@unlink($this->_dir . '/' . $file);
}
}
closedir($handle);
}
}
/**
* This method is used to check whether the cache file is valid to use.
*
* Currently it assumes that the cache file is always valid.
*
* @return True, if cache file is valid; false otherwise.
*/
protected function isValid()
{
return true;
}
}