示例#1
0
 public function testSerializeUnserialize()
 {
     $expected = 'some other random value string not unsimilar to the last random value string';
     $key = __METHOD__;
     $this->obj->set($key, $expected);
     $serialized = serialize($this->obj);
     $this->assertNotEmpty($serialized);
     /**
      * @var $unserialized RuntimeCache
      */
     $unserialized = unserialize($serialized);
     $this->assertTrue($unserialized instanceof RuntimeCache);
     $this->assertEquals($expected, $unserialized->get($key));
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     Yii::app()->cache->flush();
     RuntimeCache::$data = array();
     $this->becomeUser('User1');
 }
示例#3
0
 public function testCacheCanBeCleared()
 {
     $this->cache->set('name 1', 'Marcos');
     $this->cache->set('name 2', 'Marcos');
     $this->cache->set('name 3', 'Marcos');
     $this->assertEquals(3, count($this->cache));
     $this->cache->clear();
     $this->assertEquals(0, count($this->cache));
 }
 /**
  * Returns the RoomMembership Record for this Room
  *
  * If none Record is found, null is given
  */
 public function getMembership($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     $rCacheId = 'RoomMembership_' . $userId . "_" . $this->getOwner()->id;
     $rCacheRes = RuntimeCache::Get($rCacheId);
     if ($rCacheRes != null) {
         return $rCacheRes;
     }
     $dbResult = RoomMembership::model()->findByAttributes(array('user_id' => $userId, 'room_id' => $this->getOwner()->id));
     RuntimeCache::Set($rCacheId, $dbResult);
     return $dbResult;
 }
示例#5
0
 protected function setUp()
 {
     parent::setUp();
     Yii::app()->cache->flush();
     RuntimeCache::$data = array();
 }
示例#6
0
 /**
  * Returns a settings record by Name and Module Id
  * The result is cached.
  *
  * @param type $spaceId
  * @param type $name
  * @param type $moduleId
  * @return \HSetting
  */
 private static function GetRecord($spaceId, $name, $moduleId = "core")
 {
     if ($moduleId == "") {
         $moduleId = "core";
     }
     $cacheId = 'SpaceSetting_' . $spaceId . '_' . $name . '_' . $moduleId;
     // Check if stored in Runtime Cache
     if (RuntimeCache::Get($cacheId) !== false) {
         return RuntimeCache::Get($cacheId);
     }
     // Check if stored in Cache
     $cacheValue = Yii::app()->cache->get($cacheId);
     if ($cacheValue !== false) {
         return $cacheValue;
     }
     $condition = "";
     $params = array('name' => $name, 'space_id' => $spaceId);
     if ($moduleId != "") {
         $params['module_id'] = $moduleId;
     } else {
         $condition = "module_id IS NULL";
     }
     $record = SpaceSetting::model()->findByAttributes($params, $condition);
     if ($record == null) {
         $record = new SpaceSetting();
         $record->space_id = $spaceId;
         $record->module_id = $moduleId;
         $record->name = $name;
     } else {
         $expireTime = 3600;
         if ($record->name != 'expireTime' && $record->module_id != "cache") {
             $expireTime = HSetting::Get('expireTime', 'cache');
         }
         Yii::app()->cache->set($cacheId, $record, $expireTime);
         RuntimeCache::Set($cacheId, $record);
     }
     return $record;
 }
示例#7
0
 /**
  * Трансформировать картинку.
  * 
  * @param string $val Путь или псевдопуть к картинке.
  * @param mixed $params Параметры в формате JSON.
  * Возможные значения ключей:
  *   'w' или 'width'      -   (int)   Максимальная ширина картинки.
  *   'h' или 'height'     -   (int)   Максимальня высота картинки.
  *   'r' или 'ratio'      -   (array) Пропорции картинки. Первый элемент -(int) ширина, второй - (int) высота
  *                                    или
  *                            (string)Строка в формате (int)x(int).
  *   'q' или 'quality'    -   (int)   Качество нового изображения. Число от 10 до 100. По умолчанию - 80.
  *   'p' или 'progressive'-   (bool)  Прогрессив. 1 - да, 0 - нет.
  *   'b' или 'background' -   (string)Цвет фона для прозрачных PNG картинок. Формат: FF00A1.
  * @return string
  */
 public static function transform($val, $params = array())
 {
     if (!empty($params)) {
         $urlParams = self::getParams($val);
         if (isset($urlParams['i']) and $urlParams['i'] !== '') {
             $newParams = array('i' => $urlParams['i']);
             $r = isset($params['ratio']) ? 'ratio' : 'r';
             if (isset($params[$r])) {
                 $params['c'] = is_array($params[$r]) ? $params[$r][0] . 'x' . $params[$r][1] : $params[$r];
             }
             unset($params[$r]);
             foreach ($params as $key => &$value) {
                 $k = substr($key, 0, 1);
                 $newParams[$k] = $value;
                 $value = $k . $value;
             }
             $path = explode('/', $urlParams['i']);
             $path[count($path) - 2] .= '/' . implode(self::$config['splitter'], $params);
             $url = implode('/', $path);
             self::$temp->setParams($url, $newParams);
             return $url;
         } else {
             return false;
         }
     } else {
         return $val;
     }
 }
示例#8
0
 /**
  * clears cache
  * @return void
  */
 public function clearCache()
 {
     Yii::app()->cache->delete($this->getCacheId());
     RuntimeCache::Remove($this->getCacheId());
 }
示例#9
0
 public function testValuesCanBeSetThenReadAndIsThenUnset()
 {
     $this->cache->set('name', 'Marcos');
     $this->cache->get('name');
     $this->assertFalse($this->cache->has('name'));
 }