2016-12-12 7 views
1

私はyii2コードでyii\caching\DbCacheを使用したい場合は、私が取得:yii2 dbcacheで( 'cache')を使ってテーブルを作成するには?

Error: Table "cache" does not exist.

は、どのように私はこのテーブルを作成することができますか?

のconfig/web.php:

'cache' => [ 
     'class' => 'yii\caching\DbCache', 
    ], 

コントローラコード:

$cache = Yii::$app->cache; 
    $duration = 30; 

    if($currency == 'USD') 
    { 
     // try retrieving $data from cache 
     $data = $cache->get('getCurrencyUSD'); 
     if($data === false) 
     { 
      $url = 'wsdl file address ...'; 
      $client = new SoapClient($url); 
      $data = $client->getCurrency('USD'); 
      $cache->set('getCurrencyUSD', $data, $duration); 
      return $data; 
     } 
    } 
+0

ドキュメントを追加します。http ://www.yiiframewo rk.com/doc-2.0/yii-caching-dbcache.html#$cacheTable-detail – dungphanxuan

答えて

1

新しい移行を作成し、使用するDBキャッシュ用にfollowing example

public function up() 
{ 
    $this->createTable('{{%cache}}', [ 
     'id' => $this->char(128)->notNull(), 
     'expire' => $this->integer()->null(), 
     'data' => 'BLOB', 
    ]); 

    $this->addPrimaryKey('pk-cache', '{{%cache}}', 'id'); 
} 

public function down() 
{ 
    $this->dropTable('{{%cache}}'); 
} 
関連する問題