See Cache for common cache operations that ArrayCache supports. Unlike the Cache, ArrayCache allows the expire parameter of [[set]], [[add]], [[multiSet]] and [[multiAdd]] to be a floating point number, so you may specify the time in milliseconds (e.g. 0.1 will be 100 milliseconds). For more details and usage information on Cache, see the guide article on caching.
Since: 2.0
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends Cache
 protected function setUp()
 {
     parent::setUp();
     if (!\Yii::$app) {
         $this->mockWebApplication(['components' => ['cache' => ['class' => \yii\caching\ArrayCache::className()]]]);
     }
 }
Example #2
0
 /**
  * Actual query with caching results in local for current request
  * @inheritdoc
  */
 protected function queryInternal($method, $fetchMode = null)
 {
     if ($method !== '') {
         $rawSql = $this->getRawSql();
         $requestLocalCacheKey = implode('', [__CLASS__, $method, $fetchMode, $this->db->dsn, $this->db->username, preg_replace('/\\s+/', '', $rawSql)]);
         mb_convert_encoding($requestLocalCacheKey, 'UTF-8', 'UTF-8');
         if (($result = static::$requestLocalCache->get($requestLocalCacheKey)) !== false) {
             Yii::info('Query result served from request local cache' . PHP_EOL . 'Query: ' . VarDumper::dumpAsString($rawSql) . PHP_EOL . 'Result: ' . VarDumper::dumpAsString($result), __METHOD__);
             return $result;
         }
         static::$requestLocalCache->set('rawSql', $rawSql);
     }
     $result = parent::queryInternal($method, $fetchMode);
     if ($method !== '') {
         static::$requestLocalCache->set($requestLocalCacheKey, $result);
     }
     return $result;
 }
Example #3
0
 protected function setUp()
 {
     parent::setUp();
     $this->mockWebApplication();
     Yii::$app->set('cache', ['class' => ArrayCache::className()]);
 }