0 follower

Final Class Yiisoft\Cache\Db\DbSchemaManager

InheritanceYiisoft\Cache\Db\DbSchemaManager

Manages the cache table schema in the database.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Cache\Db\DbSchemaManager
ensureNoTable() Ensures that the cache table does not exist in the database. Yiisoft\Cache\Db\DbSchemaManager
ensureTable() Ensures that the cache table exists in the database. Yiisoft\Cache\Db\DbSchemaManager

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Db\Connection\ConnectionInterface $db )
$db \Yiisoft\Db\Connection\ConnectionInterface

                public function __construct(private readonly ConnectionInterface $db)
{
}

            
ensureNoTable() public method

Ensures that the cache table does not exist in the database.

public void ensureNoTable ( string $table '{{%yii_cache}}' )
$table string

The name of the cache table. Defaults to '{{%yii_cache}}'.

throws \Yiisoft\Db\Exception\Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws Throwable

                public function ensureNoTable(string $table = '{{%yii_cache}}'): void
{
    $rawTableName = $this->db->getQuoter()->getRawTableName($table);
    if ($this->hasTable($rawTableName)) {
        $this->db->createCommand()->dropTable($rawTableName)->execute();
    }
}

            
ensureTable() public method

Ensures that the cache table exists in the database.

public void ensureTable ( string $table '{{%yii_cache}}' )
$table string

The name of the cache table. Defaults to '{{%yii_cache}}'.

throws \Yiisoft\Db\Exception\Exception
throws \Yiisoft\Db\Exception\NotSupportedException
throws \Yiisoft\Db\Exception\InvalidConfigException
throws Throwable

                public function ensureTable(string $table = '{{%yii_cache}}'): void
{
    $tableRawName = $this->db->getQuoter()->getRawTableName($table);
    if ($this->hasTable($tableRawName)) {
        return;
    }
    $this->db->createCommand()->createTable(
        $table,
        [
            'id' => $this->db->getColumnBuilderClass()::string(128)->notNull(),
            'data' => $this->db->getColumnBuilderClass()::binary(),
            'expire' => $this->db->getColumnBuilderClass()::integer(),
            "CONSTRAINT [[PK_$tableRawName]] PRIMARY KEY ([[id]])",
        ],
    )->execute();
}