Version Notes
1.8.0.0
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | Lib_Mage |
| Version | 1.8.0.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.7.0.1 to 1.8.0.0
- lib/Mage/Archive/Tar.php +2 -5
- lib/Mage/Backup/Filesystem/Helper.php +4 -0
- lib/Mage/Cache/Backend/File.php +782 -0
- lib/Mage/Cache/Backend/Redis.php +69 -0
- package.xml +5 -5
lib/Mage/Archive/Tar.php
CHANGED
|
@@ -458,11 +458,8 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
|
|
| 458 |
$list[] = $currentFile . DS;
|
| 459 |
} elseif ($header['type'] == '2') {
|
| 460 |
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
if (false === $symlinkResult) {
|
| 464 |
-
throw new Mage_Exception('Failed to create symlink ' . $currentFile . ' to ' . $header['symlink']);
|
| 465 |
-
}
|
| 466 |
}
|
| 467 |
}
|
| 468 |
|
| 458 |
$list[] = $currentFile . DS;
|
| 459 |
} elseif ($header['type'] == '2') {
|
| 460 |
|
| 461 |
+
//we do not interrupt unpack process if symlink creation failed as symlinks are not so important
|
| 462 |
+
@symlink($header['symlink'], $currentFile);
|
|
|
|
|
|
|
|
|
|
| 463 |
}
|
| 464 |
}
|
| 465 |
|
lib/Mage/Backup/Filesystem/Helper.php
CHANGED
|
@@ -119,6 +119,10 @@ class Mage_Backup_Filesystem_Helper
|
|
| 119 |
$iterator = new Mage_Backup_Filesystem_Iterator_Filter($filesystemIterator, $skipFiles);
|
| 120 |
|
| 121 |
foreach ($iterator as $item) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if (($infoOptions & self::INFO_WRITABLE) && !$item->isWritable()) {
|
| 123 |
$info['writable'] = false;
|
| 124 |
}
|
| 119 |
$iterator = new Mage_Backup_Filesystem_Iterator_Filter($filesystemIterator, $skipFiles);
|
| 120 |
|
| 121 |
foreach ($iterator as $item) {
|
| 122 |
+
if ($item->isLink()) {
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category Mage
|
| 22 |
+
* @package Mage_Cache
|
| 23 |
+
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
+
*
|
| 26 |
+
* Summary of changes:
|
| 27 |
+
* - code modified to follow Magento coding standards
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Licensed under New BSD license http://opensource.org/licenses/BSD-3-Clause
|
| 32 |
+
* Copyright (c) 2012, Colin Mollenhour
|
| 33 |
+
* All rights reserved.
|
| 34 |
+
*
|
| 35 |
+
* Redistribution and use in source and binary forms, with or without
|
| 36 |
+
* modification, are permitted provided that the following conditions are met:
|
| 37 |
+
*
|
| 38 |
+
* * Redistributions of source code must retain the above copyright
|
| 39 |
+
* notice, this list of conditions and the following disclaimer.
|
| 40 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 41 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 42 |
+
* documentation and/or other materials provided with the distribution.
|
| 43 |
+
* * The name of Colin Mollenhour may not be used to endorse or promote products
|
| 44 |
+
* derived from this software without specific prior written permission.
|
| 45 |
+
*
|
| 46 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 47 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 48 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 49 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
| 50 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 51 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 52 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 53 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 54 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 55 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Optimized file cache backend
|
| 60 |
+
*
|
| 61 |
+
* @category Mage
|
| 62 |
+
* @package Mage_Cache
|
| 63 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
| 64 |
+
*/
|
| 65 |
+
class Mage_Cache_Backend_File extends Zend_Cache_Backend_File
|
| 66 |
+
{
|
| 67 |
+
/**
|
| 68 |
+
* Default options for the File cache adapter
|
| 69 |
+
*
|
| 70 |
+
* @var array
|
| 71 |
+
*/
|
| 72 |
+
protected $_options = array(
|
| 73 |
+
'cache_dir' => null, // Path to cache files
|
| 74 |
+
'file_locking' => true, // Best to keep enabled
|
| 75 |
+
'read_control' => false, // Use a checksum to detect corrupt data
|
| 76 |
+
'read_control_type' => 'crc32', // If read_control is enabled, which checksum algorithm to use
|
| 77 |
+
'hashed_directory_level' => 2, // How many characters should be used to create sub-directories
|
| 78 |
+
'hashed_directory_perm' => 0770, // Filesystem permissions for created directories
|
| 79 |
+
'file_name_prefix' => 'mage', // Prefix for cache directories created
|
| 80 |
+
'cache_file_perm' => 0660, // Filesystem permissions for created files
|
| 81 |
+
);
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Prevents unnecessary checks
|
| 85 |
+
*
|
| 86 |
+
* @var boolean
|
| 87 |
+
*/
|
| 88 |
+
protected $_isTagDirChecked;
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* @param array $options
|
| 92 |
+
*/
|
| 93 |
+
public function __construct(array $options = array())
|
| 94 |
+
{
|
| 95 |
+
// Backwards compatibility ZF 1.11 and ZF 1.12
|
| 96 |
+
if (isset($options['hashed_directory_umask'])) {
|
| 97 |
+
$options['hashed_directory_perm'] = $options['hashed_directory_umask'];
|
| 98 |
+
}
|
| 99 |
+
if (isset($options['cache_file_umask'])) {
|
| 100 |
+
$options['cache_file_perm'] = $options['cache_file_umask'];
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Don't use parent constructor
|
| 104 |
+
while (list($name, $value) = each($options)) {
|
| 105 |
+
$this->setOption($name, $value);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// Check cache dir
|
| 109 |
+
if ($this->_options['cache_dir'] !== null) {
|
| 110 |
+
$this->setCacheDir($this->_options['cache_dir']);
|
| 111 |
+
} else {
|
| 112 |
+
$this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Validate prefix
|
| 116 |
+
if (isset($this->_options['file_name_prefix'])) {
|
| 117 |
+
if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) {
|
| 118 |
+
Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]');
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// See #ZF-4422
|
| 123 |
+
if (is_string($this->_options['hashed_directory_perm'])) {
|
| 124 |
+
$this->_options['hashed_directory_perm'] = octdec($this->_options['hashed_directory_perm']);
|
| 125 |
+
}
|
| 126 |
+
if (is_string($this->_options['cache_file_perm'])) {
|
| 127 |
+
$this->_options['cache_file_perm'] = octdec($this->_options['cache_file_perm']);
|
| 128 |
+
}
|
| 129 |
+
$this->_options['hashed_directory_umask'] = $this->_options['hashed_directory_perm'];
|
| 130 |
+
$this->_options['cache_file_umask'] = $this->_options['cache_file_perm'];
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Trying to load cached value by id, in case of failure will return false, in other case will return cached string
|
| 135 |
+
*
|
| 136 |
+
* @param string $id Cache id
|
| 137 |
+
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
| 138 |
+
*
|
| 139 |
+
* @return string|bool Cached data or false
|
| 140 |
+
*/
|
| 141 |
+
public function load($id, $doNotTestCacheValidity = false)
|
| 142 |
+
{
|
| 143 |
+
$file = $this->_file($id);
|
| 144 |
+
$cache = $this->_getCache($file, true);
|
| 145 |
+
if (!$cache) {
|
| 146 |
+
return false;
|
| 147 |
+
}
|
| 148 |
+
list($metadatas, $data) = $cache;
|
| 149 |
+
if (!$doNotTestCacheValidity && time() > $metadatas['expire']) {
|
| 150 |
+
// ?? $this->remove($id);
|
| 151 |
+
return false;
|
| 152 |
+
}
|
| 153 |
+
if ($this->_options['read_control']) {
|
| 154 |
+
$hashData = $this->_hash($data, $this->_options['read_control_type']);
|
| 155 |
+
$hashControl = $metadatas['hash'];
|
| 156 |
+
if ($hashData != $hashControl) {
|
| 157 |
+
$this->_log(
|
| 158 |
+
'Zend_Cache_Backend_File::load() / read_control : stored hash and computed hash do not match'
|
| 159 |
+
);
|
| 160 |
+
$this->remove($id);
|
| 161 |
+
|
| 162 |
+
return false;
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
return $data;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Save some string data into a cache record
|
| 171 |
+
*
|
| 172 |
+
* Note : $data must be a "string" (serialization is done by the
|
| 173 |
+
* core not by the backend)
|
| 174 |
+
*
|
| 175 |
+
* @param string $data Data to cache
|
| 176 |
+
* @param string $id Cache id
|
| 177 |
+
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
| 178 |
+
* @param bool|int $specificLifetime If != false, set a specific lifetime for this cache record
|
| 179 |
+
* (null => infinite lifetime)
|
| 180 |
+
*
|
| 181 |
+
* @return boolean In case of success returns true
|
| 182 |
+
*/
|
| 183 |
+
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
| 184 |
+
{
|
| 185 |
+
$file = $this->_file($id);
|
| 186 |
+
$path = $this->_path($id);
|
| 187 |
+
if ($this->_options['hashed_directory_level'] > 0) {
|
| 188 |
+
if (!is_writable($path)) {
|
| 189 |
+
// maybe, we just have to build the directory structure
|
| 190 |
+
$this->_recursiveMkdirAndChmod($id);
|
| 191 |
+
if (!is_writable($path)) {
|
| 192 |
+
return false;
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
if ($this->_options['read_control']) {
|
| 197 |
+
$hash = $this->_hash($data, $this->_options['read_control_type']);
|
| 198 |
+
} else {
|
| 199 |
+
$hash = '';
|
| 200 |
+
}
|
| 201 |
+
$metadatas = array(
|
| 202 |
+
'hash' => $hash,
|
| 203 |
+
'mtime' => time(),
|
| 204 |
+
'expire' => $this->_expireTime($this->getLifetime($specificLifetime)),
|
| 205 |
+
'tags' => implode(',', $tags),
|
| 206 |
+
);
|
| 207 |
+
$res = $this->_filePutContents($file, serialize($metadatas) . "\n" . $data);
|
| 208 |
+
$res = $res && $this->_updateIdsTags(array($id), $tags, 'merge');
|
| 209 |
+
|
| 210 |
+
return $res;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* Remove a cache record
|
| 215 |
+
*
|
| 216 |
+
* @param string $id Cache id
|
| 217 |
+
*
|
| 218 |
+
* @return boolean In case of success returns true
|
| 219 |
+
*/
|
| 220 |
+
public function remove($id)
|
| 221 |
+
{
|
| 222 |
+
$file = $this->_file($id);
|
| 223 |
+
$metadatas = $this->_getCache($file, false);
|
| 224 |
+
if ($metadatas) {
|
| 225 |
+
$boolRemove = $this->_remove($file);
|
| 226 |
+
$boolTags = $this->_updateIdsTags(array($id), explode(',', $metadatas['tags']), 'diff');
|
| 227 |
+
|
| 228 |
+
return $boolRemove && $boolTags;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
return false;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Clean some cache records
|
| 236 |
+
*
|
| 237 |
+
* Available modes are :
|
| 238 |
+
* 'all' (default) => remove all cache entries ($tags is not used)
|
| 239 |
+
* 'old' => remove too old cache entries ($tags is not used)
|
| 240 |
+
* 'matchingTag' => remove cache entries matching all given tags
|
| 241 |
+
* ($tags can be an array of strings or a single string)
|
| 242 |
+
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
| 243 |
+
* ($tags can be an array of strings or a single string)
|
| 244 |
+
* 'matchingAnyTag' => remove cache entries matching any given tags
|
| 245 |
+
* ($tags can be an array of strings or a single string)
|
| 246 |
+
*
|
| 247 |
+
* @param string $mode
|
| 248 |
+
* @param array $tags
|
| 249 |
+
*
|
| 250 |
+
* @return boolean In case of success returns true
|
| 251 |
+
*/
|
| 252 |
+
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
| 253 |
+
{
|
| 254 |
+
// We use this protected method to hide the recursive stuff
|
| 255 |
+
clearstatcache();
|
| 256 |
+
switch ($mode) {
|
| 257 |
+
case Zend_Cache::CLEANING_MODE_ALL:
|
| 258 |
+
case Zend_Cache::CLEANING_MODE_OLD:
|
| 259 |
+
return $this->_clean($this->_options['cache_dir'], $mode);
|
| 260 |
+
default:
|
| 261 |
+
return $this->_cleanNew($mode, $tags);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/**
|
| 266 |
+
* Return an array of stored tags
|
| 267 |
+
*
|
| 268 |
+
* @return array Array of stored tags (string)
|
| 269 |
+
*/
|
| 270 |
+
public function getTags()
|
| 271 |
+
{
|
| 272 |
+
$prefix = $this->_tagFile('');
|
| 273 |
+
$prefixLen = strlen($prefix);
|
| 274 |
+
$tags = array();
|
| 275 |
+
foreach (@glob($prefix . '*') as $tagFile) {
|
| 276 |
+
$tags[] = substr($tagFile, $prefixLen);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
return $tags;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
/**
|
| 283 |
+
* Return an array of stored cache ids which match given tags
|
| 284 |
+
*
|
| 285 |
+
* In case of multiple tags, a logical AND is made between tags
|
| 286 |
+
*
|
| 287 |
+
* @param array $tags Array of tags
|
| 288 |
+
*
|
| 289 |
+
* @return array Array of matching cache ids (string)
|
| 290 |
+
*/
|
| 291 |
+
public function getIdsMatchingTags($tags = array())
|
| 292 |
+
{
|
| 293 |
+
return $this->_getIdsByTags(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $tags);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
* Return an array of stored cache ids which don't match given tags
|
| 298 |
+
*
|
| 299 |
+
* In case of multiple tags, a logical OR is made between tags
|
| 300 |
+
*
|
| 301 |
+
* @param array $tags Array of tags
|
| 302 |
+
*
|
| 303 |
+
* @return array Array of not matching cache ids (string)
|
| 304 |
+
*/
|
| 305 |
+
public function getIdsNotMatchingTags($tags = array())
|
| 306 |
+
{
|
| 307 |
+
return $this->_getIdsByTags(Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, $tags);
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* Return an array of stored cache ids which match any given tags
|
| 312 |
+
*
|
| 313 |
+
* In case of multiple tags, a logical OR is made between tags
|
| 314 |
+
*
|
| 315 |
+
* @param array $tags Array of tags
|
| 316 |
+
*
|
| 317 |
+
* @return array Array of any matching cache ids (string)
|
| 318 |
+
*/
|
| 319 |
+
public function getIdsMatchingAnyTags($tags = array())
|
| 320 |
+
{
|
| 321 |
+
return $this->_getIdsByTags(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
/**
|
| 325 |
+
* Return an array of metadatas for the given cache id
|
| 326 |
+
*
|
| 327 |
+
* The array must include these keys :
|
| 328 |
+
* - expire : the expire timestamp
|
| 329 |
+
* - tags : a string array of tags
|
| 330 |
+
* - mtime : timestamp of last modification time
|
| 331 |
+
*
|
| 332 |
+
* @param string $id Cache id
|
| 333 |
+
*
|
| 334 |
+
* @return array Array of metadatas (false if the cache id is not found)
|
| 335 |
+
*/
|
| 336 |
+
public function getMetadatas($id)
|
| 337 |
+
{
|
| 338 |
+
$metadatas = $this->_getCache($this->_file($id), false);
|
| 339 |
+
if ($metadatas) {
|
| 340 |
+
$metadatas['tags'] = explode(',', $metadatas['tags']);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
return $metadatas;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
/**
|
| 347 |
+
* Give (if possible) an extra lifetime to the given cache id
|
| 348 |
+
*
|
| 349 |
+
* @param string $id Cache id
|
| 350 |
+
* @param int $extraLifetime
|
| 351 |
+
*
|
| 352 |
+
* @return boolean In case of success returns true
|
| 353 |
+
*/
|
| 354 |
+
public function touch($id, $extraLifetime)
|
| 355 |
+
{
|
| 356 |
+
$file = $this->_file($id);
|
| 357 |
+
$cache = $this->_getCache($file, true);
|
| 358 |
+
if (!$cache) {
|
| 359 |
+
return false;
|
| 360 |
+
}
|
| 361 |
+
list($metadatas, $data) = $cache;
|
| 362 |
+
if (time() > $metadatas['expire']) {
|
| 363 |
+
return false;
|
| 364 |
+
}
|
| 365 |
+
$newMetadatas = array(
|
| 366 |
+
'hash' => $metadatas['hash'],
|
| 367 |
+
'mtime' => time(),
|
| 368 |
+
'expire' => $metadatas['expire'] + $extraLifetime,
|
| 369 |
+
'tags' => $metadatas['tags']
|
| 370 |
+
);
|
| 371 |
+
|
| 372 |
+
return !!$this->_filePutContents($file, serialize($newMetadatas) . "\n" . $data);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
/**
|
| 376 |
+
* Get a metadatas record and optionally the data as well
|
| 377 |
+
*
|
| 378 |
+
* @param string $file Cache file
|
| 379 |
+
* @param bool $withData
|
| 380 |
+
*
|
| 381 |
+
* @return array|bool
|
| 382 |
+
*/
|
| 383 |
+
protected function _getCache($file, $withData)
|
| 384 |
+
{
|
| 385 |
+
if (!is_file($file) || !($fd = @fopen($file, 'rb'))) {
|
| 386 |
+
return false;
|
| 387 |
+
}
|
| 388 |
+
if ($this->_options['file_locking']) {
|
| 389 |
+
flock($fd, LOCK_SH);
|
| 390 |
+
}
|
| 391 |
+
$metadata = fgets($fd);
|
| 392 |
+
if (!$metadata) {
|
| 393 |
+
if ($this->_options['file_locking']) {
|
| 394 |
+
flock($fd, LOCK_UN);
|
| 395 |
+
}
|
| 396 |
+
fclose($fd);
|
| 397 |
+
|
| 398 |
+
return false;
|
| 399 |
+
}
|
| 400 |
+
if ($withData) {
|
| 401 |
+
$data = stream_get_contents($fd);
|
| 402 |
+
}
|
| 403 |
+
if ($this->_options['file_locking']) {
|
| 404 |
+
flock($fd, LOCK_UN);
|
| 405 |
+
}
|
| 406 |
+
fclose($fd);
|
| 407 |
+
$metadata = @unserialize(rtrim($metadata, "\n"));
|
| 408 |
+
if ($withData) {
|
| 409 |
+
return array($metadata, $data);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
return $metadata;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/**
|
| 416 |
+
* Get meta data from a cache record
|
| 417 |
+
*
|
| 418 |
+
* @param string $id Cache id
|
| 419 |
+
*
|
| 420 |
+
* @return array|bool Associative array of meta data
|
| 421 |
+
*/
|
| 422 |
+
protected function _getMetadatas($id)
|
| 423 |
+
{
|
| 424 |
+
return $this->_getCache($this->_file($id), false);
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/**
|
| 428 |
+
* Set a metadatas record
|
| 429 |
+
*
|
| 430 |
+
* @param string $id Cache id
|
| 431 |
+
* @param array $metadatas Associative array of metadatas
|
| 432 |
+
* @param boolean $save Optional pass false to disable saving to file
|
| 433 |
+
*
|
| 434 |
+
* @return boolean In case of success returns true
|
| 435 |
+
*/
|
| 436 |
+
protected function _setMetadatas($id, $metadatas, $save = true)
|
| 437 |
+
{
|
| 438 |
+
// TODO - implement for unit tests ___expire method
|
| 439 |
+
return true;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
/**
|
| 443 |
+
* Return the complete directory path of a filename (including hashedDirectoryStructure)
|
| 444 |
+
*
|
| 445 |
+
* Uses multiple letters for a single-level hash rather than multiple levels
|
| 446 |
+
*
|
| 447 |
+
* @param string $id Cache id
|
| 448 |
+
* @param boolean $parts If true, returns array of directory parts instead of single string
|
| 449 |
+
*
|
| 450 |
+
* @return string Complete directory path
|
| 451 |
+
*/
|
| 452 |
+
protected function _path($id, $parts = false)
|
| 453 |
+
{
|
| 454 |
+
$partsArray = array();
|
| 455 |
+
$root = $this->_options['cache_dir'];
|
| 456 |
+
$prefix = $this->_options['file_name_prefix'];
|
| 457 |
+
if ($this->_options['hashed_directory_level'] > 0) {
|
| 458 |
+
$hash = hash('adler32', $id);
|
| 459 |
+
$root = $root . $prefix . '--' . substr($hash, -$this->_options['hashed_directory_level'])
|
| 460 |
+
. DIRECTORY_SEPARATOR;
|
| 461 |
+
$partsArray[] = $root;
|
| 462 |
+
}
|
| 463 |
+
if ($parts) {
|
| 464 |
+
return $partsArray;
|
| 465 |
+
}
|
| 466 |
+
return $root;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
/**
|
| 470 |
+
* Clean some cache records (protected method used for recursive stuff)
|
| 471 |
+
*
|
| 472 |
+
* Available modes are :
|
| 473 |
+
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
| 474 |
+
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
| 475 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
| 476 |
+
* ($tags can be an array of strings or a single string)
|
| 477 |
+
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
| 478 |
+
* ($tags can be an array of strings or a single string)
|
| 479 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
| 480 |
+
* ($tags can be an array of strings or a single string)
|
| 481 |
+
*
|
| 482 |
+
* @param string $dir Directory to clean
|
| 483 |
+
* @param string $mode Clean mode
|
| 484 |
+
* @param array $tags
|
| 485 |
+
*
|
| 486 |
+
* @throws Zend_Cache_Exception
|
| 487 |
+
* @return boolean In case of success returns true
|
| 488 |
+
*/
|
| 489 |
+
protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
| 490 |
+
{
|
| 491 |
+
if (!is_dir($dir)) {
|
| 492 |
+
return false;
|
| 493 |
+
}
|
| 494 |
+
$result = true;
|
| 495 |
+
$glob = @glob($dir . $this->_options['file_name_prefix'] . '--*');
|
| 496 |
+
if ($glob === false) {
|
| 497 |
+
return true;
|
| 498 |
+
}
|
| 499 |
+
foreach ($glob as $file) {
|
| 500 |
+
if (is_file($file)) {
|
| 501 |
+
switch ($mode) {
|
| 502 |
+
case Zend_Cache::CLEANING_MODE_ALL:
|
| 503 |
+
$result = @unlink($file) && $result;
|
| 504 |
+
continue;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
$id = $this->_fileNameToId(basename($file));
|
| 508 |
+
$_file = $this->_file($id);
|
| 509 |
+
if ($file != $_file) {
|
| 510 |
+
@unlink($file);
|
| 511 |
+
continue;
|
| 512 |
+
}
|
| 513 |
+
$metadatas = $this->_getCache($file, false);
|
| 514 |
+
if (!$metadatas) {
|
| 515 |
+
@unlink($file);
|
| 516 |
+
continue;
|
| 517 |
+
}
|
| 518 |
+
switch ($mode) {
|
| 519 |
+
case Zend_Cache::CLEANING_MODE_OLD:
|
| 520 |
+
if (time() > $metadatas['expire']) {
|
| 521 |
+
$result = $this->_remove($file) && $result;
|
| 522 |
+
$result = $this->_updateIdsTags(
|
| 523 |
+
array($id),
|
| 524 |
+
explode(',', $metadatas['tags']),
|
| 525 |
+
'diff'
|
| 526 |
+
) && $result;
|
| 527 |
+
}
|
| 528 |
+
continue;
|
| 529 |
+
default:
|
| 530 |
+
Zend_Cache::throwException('Invalid mode for clean() method');
|
| 531 |
+
break;
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
if (is_dir($file) && $this->_options['hashed_directory_level'] > 0) {
|
| 535 |
+
// Recursive call
|
| 536 |
+
$result = $this->_clean($file . DIRECTORY_SEPARATOR, $mode) && $result;
|
| 537 |
+
if ($mode == 'all') {
|
| 538 |
+
// if mode=='all', we try to drop the structure too
|
| 539 |
+
@rmdir($file);
|
| 540 |
+
}
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
if ($mode == 'all') {
|
| 544 |
+
foreach (glob($this->_tagFile('*')) as $tagFile) {
|
| 545 |
+
@unlink($tagFile);
|
| 546 |
+
}
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
return $result;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
/**
|
| 553 |
+
* Clean some cache records (protected method used for recursive stuff)
|
| 554 |
+
*
|
| 555 |
+
* Available modes are :
|
| 556 |
+
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
| 557 |
+
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
| 558 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
| 559 |
+
* ($tags can be an array of strings or a single string)
|
| 560 |
+
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
| 561 |
+
* ($tags can be an array of strings or a single string)
|
| 562 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
| 563 |
+
* ($tags can be an array of strings or a single string)
|
| 564 |
+
*
|
| 565 |
+
* @param string $mode Clean mode
|
| 566 |
+
* @param array $tags Array of tags
|
| 567 |
+
*
|
| 568 |
+
* @throws Zend_Cache_Exception
|
| 569 |
+
* @return boolean In case of success returns true
|
| 570 |
+
*/
|
| 571 |
+
protected function _cleanNew($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
| 572 |
+
{
|
| 573 |
+
$result = true;
|
| 574 |
+
$ids = $this->_getIdsByTags($mode, $tags);
|
| 575 |
+
foreach ($ids as $id) {
|
| 576 |
+
$idFile = $this->_file($id);
|
| 577 |
+
if (is_file($idFile)) {
|
| 578 |
+
$result = $result && $this->_remove($idFile);
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
switch ($mode) {
|
| 582 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
| 583 |
+
foreach ($tags as $tag) {
|
| 584 |
+
$tagFile = $this->_tagFile($tag);
|
| 585 |
+
if (is_file($tagFile)) {
|
| 586 |
+
$result = $result && $this->_remove($tagFile);
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
break;
|
| 590 |
+
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
| 591 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
| 592 |
+
$this->_updateIdsTags($ids, $tags, 'diff');
|
| 593 |
+
break;
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
return $result;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
/**
|
| 600 |
+
* Fetching cache' ids, by tags using different mods
|
| 601 |
+
*
|
| 602 |
+
* @param string $mode
|
| 603 |
+
* @param array $tags
|
| 604 |
+
*
|
| 605 |
+
* @return array
|
| 606 |
+
*/
|
| 607 |
+
protected function _getIdsByTags($mode, $tags)
|
| 608 |
+
{
|
| 609 |
+
$ids = array();
|
| 610 |
+
switch ($mode) {
|
| 611 |
+
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
| 612 |
+
$ids = $this->getIds();
|
| 613 |
+
if ($tags) {
|
| 614 |
+
foreach ($tags as $tag) {
|
| 615 |
+
if (!$ids) {
|
| 616 |
+
break; // early termination optimization
|
| 617 |
+
}
|
| 618 |
+
$ids = array_diff($ids, $this->_getTagIds($tag));
|
| 619 |
+
}
|
| 620 |
+
}
|
| 621 |
+
break;
|
| 622 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
| 623 |
+
if ($tags) {
|
| 624 |
+
$tag = array_shift($tags);
|
| 625 |
+
$ids = $this->_getTagIds($tag);
|
| 626 |
+
foreach ($tags as $tag) {
|
| 627 |
+
if (!$ids) {
|
| 628 |
+
break; // early termination optimization
|
| 629 |
+
}
|
| 630 |
+
$ids = array_intersect($ids, $this->_getTagIds($tag));
|
| 631 |
+
}
|
| 632 |
+
$ids = array_unique($ids);
|
| 633 |
+
}
|
| 634 |
+
break;
|
| 635 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
| 636 |
+
foreach ($tags as $tag) {
|
| 637 |
+
$ids = $ids + $this->_getTagIds($tag);
|
| 638 |
+
}
|
| 639 |
+
$ids = array_unique($ids);
|
| 640 |
+
break;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
return $ids;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
/**
|
| 647 |
+
* Make and return a file name (with path)
|
| 648 |
+
*
|
| 649 |
+
* @param string $id Cache id
|
| 650 |
+
*
|
| 651 |
+
* @return string File name (with path)
|
| 652 |
+
*/
|
| 653 |
+
protected function _tagFile($id)
|
| 654 |
+
{
|
| 655 |
+
return $this->_tagPath() . $this->_idToFileName($id);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
/**
|
| 659 |
+
* Return the complete directory path where tags are stored
|
| 660 |
+
*
|
| 661 |
+
* @return string Complete directory path
|
| 662 |
+
*/
|
| 663 |
+
protected function _tagPath()
|
| 664 |
+
{
|
| 665 |
+
$path = $this->_options['cache_dir'] . DIRECTORY_SEPARATOR . $this->_options['file_name_prefix'] . '--tags'
|
| 666 |
+
. DIRECTORY_SEPARATOR;
|
| 667 |
+
if (!$this->_isTagDirChecked) {
|
| 668 |
+
if (!is_dir($path)) {
|
| 669 |
+
@mkdir($path, $this->_options['hashed_directory_perm']);
|
| 670 |
+
@chmod($path, $this->_options['hashed_directory_perm']);
|
| 671 |
+
}
|
| 672 |
+
$this->_isTagDirChecked = true;
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
return $path;
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
/**
|
| 679 |
+
* Fetching all existed tags' ids
|
| 680 |
+
*
|
| 681 |
+
* @param string|resource $tag
|
| 682 |
+
*
|
| 683 |
+
* @return array
|
| 684 |
+
*/
|
| 685 |
+
protected function _getTagIds($tag)
|
| 686 |
+
{
|
| 687 |
+
if (is_resource($tag)) {
|
| 688 |
+
$ids = stream_get_contents($tag);
|
| 689 |
+
} else {
|
| 690 |
+
$ids = @file_get_contents($this->_tagFile($tag));
|
| 691 |
+
}
|
| 692 |
+
if (!$ids) {
|
| 693 |
+
return array();
|
| 694 |
+
}
|
| 695 |
+
$ids = substr($ids, 0, strrpos($ids, "\n"));
|
| 696 |
+
|
| 697 |
+
return explode("\n", $ids);
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
/**
|
| 701 |
+
* Updating tags' ids
|
| 702 |
+
*
|
| 703 |
+
* @param array $ids
|
| 704 |
+
* @param array $tags
|
| 705 |
+
* @param string $mode
|
| 706 |
+
*
|
| 707 |
+
* @return boolean
|
| 708 |
+
*/
|
| 709 |
+
protected function _updateIdsTags($ids, $tags, $mode)
|
| 710 |
+
{
|
| 711 |
+
$result = true;
|
| 712 |
+
foreach ($tags as $tag) {
|
| 713 |
+
$file = $this->_tagFile($tag);
|
| 714 |
+
if (file_exists($file)) {
|
| 715 |
+
if (!$ids && $mode == 'diff') {
|
| 716 |
+
$result = $this->_remove($file);
|
| 717 |
+
} else {
|
| 718 |
+
if ($mode == 'diff' || (rand(1, 100) == 1 && filesize($file) > 4096)) {
|
| 719 |
+
$file = $this->_tagFile($tag);
|
| 720 |
+
if (!($fd = fopen($file, 'rb+'))) {
|
| 721 |
+
$result = false;
|
| 722 |
+
continue;
|
| 723 |
+
}
|
| 724 |
+
if ($this->_options['file_locking']) {
|
| 725 |
+
flock($fd, LOCK_EX);
|
| 726 |
+
}
|
| 727 |
+
if ($mode == 'diff') {
|
| 728 |
+
$_ids = array_diff($this->_getTagIds($fd), $ids);
|
| 729 |
+
} else { // if ($mode == 'merge')
|
| 730 |
+
$_ids = $this->_getTagIds($fd) + $ids;
|
| 731 |
+
}
|
| 732 |
+
fseek($fd, 0);
|
| 733 |
+
ftruncate($fd, 0);
|
| 734 |
+
$result = fwrite($fd, implode("\n", array_unique($_ids)) . "\n") && $result;
|
| 735 |
+
if ($this->_options['file_locking']) {
|
| 736 |
+
flock($fd, LOCK_UN);
|
| 737 |
+
}
|
| 738 |
+
fclose($fd);
|
| 739 |
+
} else {
|
| 740 |
+
$string = implode("\n", $ids) . "\n";
|
| 741 |
+
$flags = FILE_APPEND | ($this->_options['file_locking'] ? LOCK_EX : 0);
|
| 742 |
+
|
| 743 |
+
$result = file_put_contents($file, $string, $flags) && $result;
|
| 744 |
+
}
|
| 745 |
+
}
|
| 746 |
+
} else {
|
| 747 |
+
if ($mode == 'merge') {
|
| 748 |
+
$result = $this->_filePutContents($file, implode("\n", $ids) . "\n") && $result;
|
| 749 |
+
}
|
| 750 |
+
}
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
return $result;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
/**
|
| 757 |
+
* Put the given string into the given file
|
| 758 |
+
*
|
| 759 |
+
* @param string $file File complete path
|
| 760 |
+
* @param string $string String to put in file
|
| 761 |
+
*
|
| 762 |
+
* @return boolean In case of success returns true
|
| 763 |
+
*/
|
| 764 |
+
protected function _filePutContents($file, $string)
|
| 765 |
+
{
|
| 766 |
+
$result = @file_put_contents($file, $string, $this->_options['file_locking'] ? LOCK_EX : 0);
|
| 767 |
+
$result && chmod($file, $this->_options['cache_file_perm']);
|
| 768 |
+
|
| 769 |
+
return $result;
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
/**
|
| 773 |
+
* For unit testing only
|
| 774 |
+
*
|
| 775 |
+
* @param $id
|
| 776 |
+
*/
|
| 777 |
+
public function ___expire($id)
|
| 778 |
+
{
|
| 779 |
+
$metadata = $this->_getMetadatas($id);
|
| 780 |
+
$this->touch($id, 1 - $metadata['expire']);
|
| 781 |
+
}
|
| 782 |
+
}
|
lib/Mage/Cache/Backend/Redis.php
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category Mage
|
| 22 |
+
* @package Mage_Cache
|
| 23 |
+
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
+
*
|
| 26 |
+
* Summary of changes:
|
| 27 |
+
* - code modified to follow Magento coding standards
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Licensed under New BSD license http://opensource.org/licenses/BSD-3-Clause
|
| 32 |
+
* Copyright (c) 2012, Colin Mollenhour
|
| 33 |
+
* All rights reserved.
|
| 34 |
+
*
|
| 35 |
+
* Redistribution and use in source and binary forms, with or without
|
| 36 |
+
* modification, are permitted provided that the following conditions are met:
|
| 37 |
+
*
|
| 38 |
+
* * Redistributions of source code must retain the above copyright
|
| 39 |
+
* notice, this list of conditions and the following disclaimer.
|
| 40 |
+
* * Redistributions in binary form must reproduce the above copyright
|
| 41 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 42 |
+
* documentation and/or other materials provided with the distribution.
|
| 43 |
+
* * The name of Colin Mollenhour may not be used to endorse or promote products
|
| 44 |
+
* derived from this software without specific prior written permission.
|
| 45 |
+
*
|
| 46 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 47 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 48 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 49 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
| 50 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 51 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 52 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 53 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 54 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 55 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Optimized file cache backend
|
| 60 |
+
*
|
| 61 |
+
* @deprecated after 1.8.0.0
|
| 62 |
+
*
|
| 63 |
+
* @category Mage
|
| 64 |
+
* @package Mage_Cache
|
| 65 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
| 66 |
+
*/
|
| 67 |
+
class Mage_Cache_Backend_Redis extends Cm_Cache_Backend_Redis
|
| 68 |
+
{
|
| 69 |
+
}
|
package.xml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Lib_Mage</name>
|
| 4 |
-
<version>1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Mage Library</summary>
|
| 10 |
<description>Mage Library</description>
|
| 11 |
-
<notes>1.
|
| 12 |
<authors><author><name>Magento Core Team</name><user>core</user><email>core@magentocommerce.com</email></author></authors>
|
| 13 |
-
<date>
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="magelib"><dir name="Mage"><dir name="Archive"><file name="Abstract.php" hash="6324215ec8ab3c55730c57976b7cd4f7"/><file name="Bz.php" hash="6485bb0cd67f6f5dfa11b8ba29e23d43"/><file name="Gz.php" hash="7f75dbebd125a0d4c27803d4ca4983f4"/><dir name="Helper"><dir name="File"><file name="Bz.php" hash="ec70e019f9031c2c2f16c9f910434352"/><file name="Gz.php" hash="84d1f376a78efa1898f888c854faf040"/></dir><file name="File.php" hash="8a0383c1b32cdbc8c53ba551c7814bda"/></dir><file name="Interface.php" hash="283914c36fdcf9851ec651149176fff7"/><file name="Tar.php" hash="
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Lib_Mage</name>
|
| 4 |
+
<version>1.8.0.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Mage Library</summary>
|
| 10 |
<description>Mage Library</description>
|
| 11 |
+
<notes>1.8.0.0</notes>
|
| 12 |
<authors><author><name>Magento Core Team</name><user>core</user><email>core@magentocommerce.com</email></author></authors>
|
| 13 |
+
<date>2013-09-24</date>
|
| 14 |
+
<time>09:09:43</time>
|
| 15 |
+
<contents><target name="magelib"><dir name="Mage"><dir name="Archive"><file name="Abstract.php" hash="6324215ec8ab3c55730c57976b7cd4f7"/><file name="Bz.php" hash="6485bb0cd67f6f5dfa11b8ba29e23d43"/><file name="Gz.php" hash="7f75dbebd125a0d4c27803d4ca4983f4"/><dir name="Helper"><dir name="File"><file name="Bz.php" hash="ec70e019f9031c2c2f16c9f910434352"/><file name="Gz.php" hash="84d1f376a78efa1898f888c854faf040"/></dir><file name="File.php" hash="8a0383c1b32cdbc8c53ba551c7814bda"/></dir><file name="Interface.php" hash="283914c36fdcf9851ec651149176fff7"/><file name="Tar.php" hash="123ee3d7c52d7319de903bf3e9422aa9"/></dir><file name="Archive.php" hash="1e0342bbcb89d417c7ee77ad3387938d"/><dir name="Autoload"><file name="Simple.php" hash="0112e880807596fbe8822be12314f14f"/></dir><dir name="Backup"><file name="Abstract.php" hash="4ab32913f5831b4e449486a5cf84d07e"/><dir name="Archive"><file name="Tar.php" hash="b6b2731bfa267b6b5fcb28d3f8f8cdbf"/></dir><file name="Db.php" hash="58001faa3a70a54441f45de8cb77aacb"/><dir name="Exception"><file name="CantLoadSnapshot.php" hash="67e47d7b54e466ebf0230810bec31158"/><file name="FtpConnectionFailed.php" hash="54cc1c76345d5fc601f7cf3af67151f6"/><file name="FtpValidationFailed.php" hash="51847fdeb1539094b9eca84b601ca241"/><file name="NotEnoughFreeSpace.php" hash="5a95f8877b4b8ca8936c0fc88a1a65ac"/><file name="NotEnoughPermissions.php" hash="b89a417fc74cc6b45371967c9c7a3e92"/></dir><file name="Exception.php" hash="b10632f40d57f0768f8d1058b0fd10fc"/><dir name="Filesystem"><file name="Helper.php" hash="981b2a7ff2ffc271c541c77e137f1627"/><dir name="Iterator"><file name="File.php" hash="0bfe672a2e72af47c777f7321b0752aa"/><file name="Filter.php" hash="f994e954d22007498e4078345aeadd20"/></dir><dir name="Rollback"><file name="Abstract.php" hash="90a2781c3c6443e08aeb3b6f1d21f97f"/><file name="Fs.php" hash="c76f9c2e09d37d4dcc785fab7d4e02b0"/><file name="Ftp.php" hash="ebea4f77dee7cc83444da16b7d51e397"/></dir></dir><file name="Filesystem.php" hash="8da3a28a9f90091105121dee17cfa142"/><file name="Interface.php" hash="5507294967fc6a5472aa82df60a1bf69"/><file name="Media.php" hash="fd2d608b2b5afaab2f33f67b5155e14b"/><file name="Nomedia.php" hash="da38dbea4586952e20d327b3af1347ae"/><file name="Snapshot.php" hash="2e4ce7ed1b78c4dbad25221abbb4aaf2"/></dir><file name="Backup.php" hash="56bf7a531ab332a0f10821e5d583afc4"/><dir name="Cache"><dir name="Backend"><file name="File.php" hash="42f4f35ddc14528a2351cad9c6861a8e"/><file name="Redis.php" hash="830130fc2d5acabbe171920e5e14d982"/></dir></dir><dir name="Connect"><dir name="Channel"><file name="Generator.php" hash="a1f115e909680bca8c1b1f0940244b13"/><file name="Parser.php" hash="ec2e7380ec4bca81de2795f96975e778"/><file name="VO.php" hash="870a1b9b28d85dd72b2b1e2529dca354"/></dir><dir name="Command"><file name="Channels_Header.php" hash="934366a4daa1ebe87b25cb9dfa061798"/><file name="Channels.php" hash="12f730285615329cba0b570385009837"/><file name="Config_Header.php" hash="119a103ed71b326993756961b6c7c2a0"/><file name="Config.php" hash="5091776f35732d8b0ff12c8ff3561c69"/><file name="Install_Header.php" hash="71f0b6bad2f745235352d181bcc66645"/><file name="Install.php" hash="2f7227a1f4003d6ce6edec4a0ce02e0f"/><file name="Package_Header.php" hash="dc3840a95f89ef844df40c585582815d"/><file name="Package.php" hash="b36bdc6a3c0f6bc9d7766a37c046a481"/><file name="Registry_Header.php" hash="559edbac0f3d267c8ca289e526b940d1"/><file name="Registry.php" hash="f9fde28940ff38dbc336335d575a295d"/><file name="Remote_Header.php" hash="4b56cd683710de6c81241f902570ba25"/><file name="Remote.php" hash="6f959617993d58aec974d578921b6212"/></dir><file name="Command.php" hash="0d474da0956a292aa83e88da4975c527"/><file name="Config.php" hash="511f752123ccc6c148a6a308fc3f81b2"/><file name="Converter.php" hash="1cde84613c6079050bb3824aba3b380d"/><dir name="Frontend"><file name="CLI.php" hash="86e6631d9345d5bf9d15148cfdace3bf"/></dir><file name="Frontend.php" hash="0a97c590fdc9844b225638d631315d35"/><file name="Ftp.php" hash="2b87de89c19712ae22756b11c763e137"/><dir name="Loader"><file name="Ftp.php" hash="0ca46737d25bf0eb321414f2d8b7ced0"/></dir><file name="Loader.php" hash="009d6f986d5ff406f7e94d2b395f6e25"/><dir name="Package"><file name="Extension.php" hash="68b329da9893e34099c7d8ad5cb9c940"/><file name="Hotfix.php" hash="850bd23783a77dbf6f50b4f169c2c7b3"/><file name="Maintainer.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Reader.php" hash="ca384e066ac21168e0a7aebc5da869c1"/><file name="Target.php" hash="351af5965f7870d3f4e960d402805b17"/><file name="VO.php" hash="9ffbdff9210474b68db7caddf9a5fe5a"/><file name="Writer.php" hash="431f107ab2ffd1977f74a94ae16481d1"/></dir><file name="Package.php" hash="bf5af87c29959f229de7b69d1d94f1e0"/><file name="Packager.php" hash="42efcb63cc3b9dbbc5e8eb98b2d8d08e"/><dir name="Repository"><file name="Abstract.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><dir name="Channel"><file name="Abstract.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Commercial.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Community.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Core.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><file name="Channel.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Local.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><file name="Repository.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Rest.php" hash="ba2d2365fc989274940e1fdff6476875"/><file name="Singleconfig.php" hash="975c04d57cbce24327e84a93d9f5443e"/><dir name="Structures"><file name="Graph.php" hash="b85283fd2af6fd54fb748cb6ea933842"/><file name="Node.php" hash="26a7e4041c3d2fd93bfdc3c692c85ede"/></dir><file name="Validator.php" hash="3ac1b21ec703073d5dd9b5dda3471fe8"/></dir><dir name="DB"><file name="Exception.php" hash="e0b55d77af8e215135ef223f593832ad"/><file name="Mysqli.php" hash="5057ea65f441bbb00c7e55298e9252a4"/></dir><file name="Exception.php" hash="807f6335110c3d6fa0cf5072e2be7892"/><dir name="HTTP"><dir name="Client"><file name="Curl.php" hash="f537a9879781ec3fe2748677bee43737"/><file name="Socket.php" hash="7a889fed729d92eba849d6fdfa32d7d6"/></dir><file name="Client.php" hash="7072f9366680bc5ebc1c447700193cb4"/><file name="IClient.php" hash="88a4a88a31a05a2154d430d7b4308ff6"/></dir><dir name="System"><file name="Args.php" hash="46467e1069edf432030d14dd59fa73df"/><file name="Dirs.php" hash="4edad790aedfbd404df28af9d2f2bea6"/><file name="Ftp.php" hash="6fc28c56dde7613be3da7b9f766caa51"/></dir><dir name="Xml"><file name="Generator.php" hash="0ddc93b0c75885f67d049d0a38c630fa"/><file name="Parser.php" hash="b2bdc0880cd5bc2d82468ee075e783a2"/></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
