Last active
March 26, 2021 09:13
-
-
Save Nex-Otaku/cf742040ec29265308d23d7da53e1a7e to your computer and use it in GitHub Desktop.
Yii2 trait for caching table schema in memory, speeds up creating object significantly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use this in ActiveRecord models to speed up creating objects 10x times | |
*/ | |
trait CachedSchemaTrait | |
{ | |
public static function getTableSchema() | |
{ | |
static $cache; | |
if ($cache === null) { | |
$cache = parent::getTableSchema(); | |
} | |
return $cache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment