Browse Source

Fixed Memcache duration which exceeds 30 days

tags/3.0.0-alpha1
Nikita Verkhovin 9 years ago
parent
commit
abb4d6f353
  1. 3
      framework/CHANGELOG.md
  2. 19
      framework/caching/MemCache.php

3
framework/CHANGELOG.md

@ -20,6 +20,7 @@ Yii Framework 2 Change Log
- Bug #9596: Fixed `\yii\web\UrlManager::createAbsoluteUrl(['site/index', '#' => 'testHash'])` losing hash (alchimik, samdark)
- Bug #9678: `I18N::format()` wasn't able to handle named placeholder in "selectordinal" (samdark)
- Bug #9681: `Json::encode()` was erroring under CYGWIN (samdark)
- Bug #9707: Fixed Memcache duration which exceeds 30 days (vernik91)
- Bug #9714: Fixed `yii\rbac\PhpManager::updateItem()` unable to save users assignments (rezident1307)
- Bug #9754: Fixed `yii\web\Request` error when path info is empty (dynasource)
- Bug #9791: Fixed endless loop on file creation for non-existing device letters on windows (lukos, cebe)
@ -30,12 +31,12 @@ Yii Framework 2 Change Log
- Bug #9924: Fixed `yii.js` handleAction corrupted parameter values containing quote (") character (silverfire)
- Bug #9984: Fixed wrong captcha color in case Imagick is used (DrDeath72)
- Bug: Fixed generation of canonical URLs for `ViewAction` pages (samdark)
- Enh #8649: Added total applied migrations to final report (vernik91)
- Enh #3506: Added `\yii\validators\IpValidator` to perform validation of IP addresses and subnets (SilverFire, samdark)
- Enh #5146: Added `\yii\i18n\Formatter::asDuration()` method (nineinchnick, SilverFire)
- Enh #7341: Client validation now skips disabled inputs (SamMousa)
- Enh #7581: Added ability to specify range using anonymous function in `RangeValidator` (RomeroMsk)
- Enh #8613: `yii\widgets\FragmentCache` will not store empty content anymore which fixes some problems related to `yii\filters\PageCache` (kidol)
- Enh #8649: Added total applied migrations to final report (vernik91)
- Enh #9476: Added DI injection via controller action method signature (mdmunir)
- Enh #9635: Added default CSS class for `\yii\grid\ActionColumn` header (arogachev, dynasource)
- Enh #9643: Added migrations for DB cache (mdmunir)

19
framework/caching/MemCache.php

@ -7,6 +7,7 @@
namespace yii\caching;
use Yii;
use yii\base\InvalidConfigException;
/**
@ -288,6 +289,7 @@ class MemCache extends Cache
*/
protected function setValue($key, $value, $duration)
{
$duration = $this->trimDuration($duration);
$expire = $duration > 0 ? $duration + time() : 0;
return $this->useMemcached ? $this->_cache->set($key, $value, $expire) : $this->_cache->set($key, $value, 0, $expire);
@ -301,6 +303,8 @@ class MemCache extends Cache
*/
protected function setValues($data, $duration)
{
$duration = $this->trimDuration($duration);
if ($this->useMemcached) {
$this->_cache->setMulti($data, $duration > 0 ? $duration + time() : 0);
@ -321,6 +325,7 @@ class MemCache extends Cache
*/
protected function addValue($key, $value, $duration)
{
$duration = $this->trimDuration($duration);
$expire = $duration > 0 ? $duration + time() : 0;
return $this->useMemcached ? $this->_cache->add($key, $value, $expire) : $this->_cache->add($key, $value, 0, $expire);
@ -346,4 +351,18 @@ class MemCache extends Cache
{
return $this->_cache->flush();
}
/**
* Trims duration to 30 days (2592000 seconds).
* @param integer $duration the number of seconds
* @return int the duration
*/
protected function trimDuration($duration)
{
if ($duration > 2592000) {
Yii::warning('Duration has been truncated to 30 days due to Memcache/Memcached limitation.', __METHOD__);
return 2592000;
}
return $duration;
}
}

Loading…
Cancel
Save