Skip to content

Instantly share code, notes, and snippets.

@Nex-Otaku
Last active March 26, 2021 09:13
Show Gist options
  • Save Nex-Otaku/cf742040ec29265308d23d7da53e1a7e to your computer and use it in GitHub Desktop.
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
<?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