setCacheMetadata($cacheKey); } /** * {@inheritDoc} * */ public function describe(string $name, array $options = []): TableSchemaInterface { $options += ['forceRefresh' => false]; $cacheConfig = $this->getCacheMetadata(); $cacheKey = $this->cacheKey($name); if (!empty($cacheConfig) && !$options['forceRefresh']) { $cached = Cache::read($cacheKey, $cacheConfig); if ($cached !== null) { return $cached; } } $table = parent::describe($name, $options); if (!empty($cacheConfig)) { Cache::write($cacheKey, $table, $cacheConfig); } return $table; } /** * Get the cache key for a given name. * * @param string $name The name to get a cache key for. * @return string The cache key. */ public function cacheKey(string $name): string { return $this->_connection->configName() . '_' . $name; } /** * Sets the cache config name to use for caching table metadata, or * disables it if false is passed. * * @param string|bool $enable Whether or not to enable caching * @return $this */ public function setCacheMetadata($enable) { if ($enable === true) { $enable = '_cake_model_'; } $this->_cache = $enable; return $this; } /** * Gets the cache config name to use for caching table metadata, false means disabled. * * @return string|bool */ public function getCacheMetadata() { return $this->_cache; } }