13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Cache |
16 * @package Zend_Cache |
17 * @subpackage Zend_Cache_Backend |
17 * @subpackage Zend_Cache_Backend |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: File.php 24844 2012-05-31 19:01:36Z rob $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_Cache_Backend_Interface |
24 * @see Zend_Cache_Backend_Interface |
25 */ |
25 */ |
32 |
32 |
33 |
33 |
34 /** |
34 /** |
35 * @package Zend_Cache |
35 * @package Zend_Cache |
36 * @subpackage Zend_Cache_Backend |
36 * @subpackage Zend_Cache_Backend |
37 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
37 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
38 * @license http://framework.zend.com/license/new-bsd New BSD License |
38 * @license http://framework.zend.com/license/new-bsd New BSD License |
39 */ |
39 */ |
40 class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface |
40 class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface |
41 { |
41 { |
42 /** |
42 /** |
118 /** |
118 /** |
119 * Constructor |
119 * Constructor |
120 * |
120 * |
121 * @param array $options associative array of options |
121 * @param array $options associative array of options |
122 * @throws Zend_Cache_Exception |
122 * @throws Zend_Cache_Exception |
123 * @return void |
|
124 */ |
123 */ |
125 public function __construct(array $options = array()) |
124 public function __construct(array $options = array()) |
126 { |
125 { |
127 parent::__construct($options); |
126 parent::__construct($options); |
128 if ($this->_options['cache_dir'] !== null) { // particular case for this option |
127 if ($this->_options['cache_dir'] !== null) { // particular case for this option |
232 * Save some string datas into a cache record |
231 * Save some string datas into a cache record |
233 * |
232 * |
234 * Note : $data is always "string" (serialization is done by the |
233 * Note : $data is always "string" (serialization is done by the |
235 * core not by the backend) |
234 * core not by the backend) |
236 * |
235 * |
237 * @param string $data Datas to cache |
236 * @param string $data Datas to cache |
238 * @param string $id Cache id |
237 * @param string $id Cache id |
239 * @param array $tags Array of strings, the cache record will be tagged by each string entry |
238 * @param array $tags Array of strings, the cache record will be tagged by each string entry |
240 * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) |
239 * @param boolean|int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) |
241 * @return boolean true if no problem |
240 * @return boolean true if no problem |
242 */ |
241 */ |
243 public function save($data, $id, $tags = array(), $specificLifetime = false) |
242 public function save($data, $id, $tags = array(), $specificLifetime = false) |
244 { |
243 { |
245 clearstatcache(); |
244 clearstatcache(); |
301 * ($tags can be an array of strings or a single string) |
300 * ($tags can be an array of strings or a single string) |
302 * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags |
301 * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags |
303 * ($tags can be an array of strings or a single string) |
302 * ($tags can be an array of strings or a single string) |
304 * |
303 * |
305 * @param string $mode clean mode |
304 * @param string $mode clean mode |
306 * @param tags array $tags array of tags |
305 * @param array $tags array of tags |
307 * @return boolean true if no problem |
306 * @return boolean true if no problem |
308 */ |
307 */ |
309 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) |
308 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) |
310 { |
309 { |
311 // We use this protected method to hide the recursive stuff |
310 // We use this protected method to hide the recursive stuff |
673 $glob = @glob($dir . $prefix . '--*'); |
672 $glob = @glob($dir . $prefix . '--*'); |
674 if ($glob === false) { |
673 if ($glob === false) { |
675 // On some systems it is impossible to distinguish between empty match and an error. |
674 // On some systems it is impossible to distinguish between empty match and an error. |
676 return true; |
675 return true; |
677 } |
676 } |
|
677 $metadataFiles = array(); |
678 foreach ($glob as $file) { |
678 foreach ($glob as $file) { |
679 if (is_file($file)) { |
679 if (is_file($file)) { |
680 $fileName = basename($file); |
680 $fileName = basename($file); |
681 if ($this->_isMetadatasFile($fileName)) { |
681 if ($this->_isMetadatasFile($fileName)) { |
682 // in CLEANING_MODE_ALL, we drop anything, even remainings old metadatas files |
682 // In CLEANING_MODE_ALL, we drop anything, even remainings old metadatas files. |
683 if ($mode != Zend_Cache::CLEANING_MODE_ALL) { |
683 // To do that, we need to save the list of the metadata files first. |
684 continue; |
684 if ($mode == Zend_Cache::CLEANING_MODE_ALL) { |
|
685 $metadataFiles[] = $file; |
685 } |
686 } |
|
687 continue; |
686 } |
688 } |
687 $id = $this->_fileNameToId($fileName); |
689 $id = $this->_fileNameToId($fileName); |
688 $metadatas = $this->_getMetadatas($id); |
690 $metadatas = $this->_getMetadatas($id); |
689 if ($metadatas === FALSE) { |
691 if ($metadatas === FALSE) { |
690 $metadatas = array('expire' => 1, 'tags' => array()); |
692 $metadatas = array('expire' => 1, 'tags' => array()); |
691 } |
693 } |
692 switch ($mode) { |
694 switch ($mode) { |
693 case Zend_Cache::CLEANING_MODE_ALL: |
695 case Zend_Cache::CLEANING_MODE_ALL: |
694 $res = $this->remove($id); |
696 $result = $result && $this->remove($id); |
695 if (!$res) { |
|
696 // in this case only, we accept a problem with the metadatas file drop |
|
697 $res = $this->_remove($file); |
|
698 } |
|
699 $result = $result && $res; |
|
700 break; |
697 break; |
701 case Zend_Cache::CLEANING_MODE_OLD: |
698 case Zend_Cache::CLEANING_MODE_OLD: |
702 if (time() > $metadatas['expire']) { |
699 if (time() > $metadatas['expire']) { |
703 $result = $this->remove($id) && $result; |
700 $result = $this->remove($id) && $result; |
704 } |
701 } |