3 * Class Minify_Cache_File
7 class Minify_Cache_File {
9 public function __construct($path = '', $fileLocking = false)
12 require_once 'Solar/Dir.php';
13 $path = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
15 $this->_locking = $fileLocking;
20 * Write data to cache.
22 * @param string $id cache id (e.g. a filename)
26 * @return bool success
28 public function store($id, $data)
30 $flag = $this->_locking
\r
33 if (is_file($this->_path . '/' . $id)) {
\r
34 @unlink($this->_path . '/' . $id);
\r
36 if (! @file_put_contents($this->_path . '/' . $id, $data, $flag)) {
\r
40 if ($data !== $this->fetch($id)) {
\r
48 * Get the size of a cache entry
50 * @param string $id cache id (e.g. a filename)
52 * @return int size in bytes
54 public function getSize($id)
56 return filesize($this->_path . '/' . $id);
60 * Does a valid cache entry exist?
62 * @param string $id cache id (e.g. a filename)
64 * @param int $srcMtime mtime of the original source file(s)
68 public function isValid($id, $srcMtime)
70 $file = $this->_path . '/' . $id;
71 return (is_file($file) && (filemtime($file) >= $srcMtime));
75 * Send the cached content to output
77 * @param string $id cache id (e.g. a filename)
79 public function display($id)
81 if ($this->_locking) {
\r
82 $fp = fopen($this->_path . '/' . $id, 'rb');
\r
83 flock($fp, LOCK_SH);
\r
85 flock($fp, LOCK_UN);
\r
88 readfile($this->_path . '/' . $id);
\r
93 * Fetch the cached content
95 * @param string $id cache id (e.g. a filename)
99 public function fetch($id)
101 if ($this->_locking) {
\r
102 $fp = fopen($this->_path . '/' . $id, 'rb');
\r
103 flock($fp, LOCK_SH);
\r
104 $ret = stream_get_contents($fp);
\r
105 flock($fp, LOCK_UN);
\r
109 return file_get_contents($this->_path . '/' . $id);
\r
114 * Fetch the cache path used
118 public function getPath()
123 private $_path = null;
124 private $_locking = null;
\r