phalcon/cphalcon · warning · Phalcon\Mvc\Model\MetaData\Exceptions\MetaDataStrategyFailed
Failed to store metaData to the cache adapter
Error message
Failed to store metaData to the cache adapter
What it means
After metadata is computed on a cache miss, MetaData::write() persists it with adapter->set(key, data). If that call returns false or throws (backend down, wrong credentials, unwritable directory, oversized payload), write() consults the orm.exception_on_failed_metadata_save setting (also settable via Phalcon\Mvc\Model\Model::setup(['exceptionOnFailedMetaDataSave' => ...])): with the setting enabled it throws MetaDataStrategyFailed, otherwise it raises a PHP warning via trigger_error(). The computed metadata still works in memory for the current request — only persistence failed.
Source
Thrown at phalcon/Mvc/Model/MetaData.zep:1063
unset(this->pendingMetaDataWrites[key]);
}
}
return true;
}
return false;
}
/**
* Throws an exception when the metadata cannot be written
*/
private function throwWriteException(var option) -> void
{
string message;
let message = "Failed to store metaData to the cache adapter";
if option {
throw new MetaDataStrategyFailed(message);
} else {
trigger_error(message);
}
}
}
View on GitHub (pinned to b7419de9cd)
Solutions
- Restore the backend: verify connectivity, credentials, and (for Stream) that the metadata directory exists, is writable, and has space.
- Delete stale or poisoned 'meta-*' entries so the next write carries a clean payload.
- If requests must survive cache outages, keep orm.exception_on_failed_metadata_save off (write failures then only warn) — but alert on the warning.
- Match the adapter's serializer with what the backend supports on every node.
Example fix
// before: Stream adapter writing to a read-only directory
$metaData = new Phalcon\Mvc\Model\MetaData\Stream([
'metaDataDir' => '/var/www/app/config/', // not writable -> write fails
]);
// after
$metaData = new Phalcon\Mvc\Model\MetaData\Stream([
'metaDataDir' => '/var/www/app/cache/metadata/', // writable, shipped empty
]); Defensive patterns
Strategy: fallback
Validate before calling
// Pre-flight: prove the metadata backend accepts writes before the first model query
$probe = new Phalcon\Cache\Adapter\Redis($redisOptions); // same backend settings as MetaData
if (!$probe->set('meta-healthcheck', 1)) {
$di->setShared('modelsMetadata', new Phalcon\Mvc\Model\MetaData\Memory());
} Try / catch
use Phalcon\Mvc\Model\MetaData\Exceptions\MetaDataStrategyFailed;
try {
$invoices = Invoices::find(); // first query computes and stores metadata
} catch (MetaDataStrategyFailed $e) {
$logger->error('metadata backend write failed: ' . $e->getMessage());
$di->setShared('modelsMetadata', new Phalcon\Mvc\Model\MetaData\Memory()); // degrade gracefully
$invoices = Invoices::find();
} Prevention
- Monitor cache backend health and disk space for Stream metadata directories.
- Keep orm.exception_on_failed_metadata_save off unless cache outages should be hard failures.
- Include a metadata write smoke check in deploy scripts and alert on trigger_error warnings.
When it happens
Trigger: The first model query of a process after a deployment (cache miss triggers write) while the metadata backend refuses writes: Redis/Libmemcached unreachable or read-only, Stream adapter's metaDataDir lacking write permission or disk space, or an adapter whose set() returns false.
Common situations: Cache node restarts during deploys; container images where the metadata directory is read-only; permission changes on cache/metadata; transient network failures to Redis; enabling exceptionOnFailedMetaDataSave and then hitting a routine cache outage.
Related errors
- Identity column '{identityField}' isn't part of the table co
- Column '{column}' have not defined a data type in '{classNam
- Column '{column}' isn't part of the table columns in '{class
- The meta-data is invalid or is corrupt
- A dependency injection container is required to access inter
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/4be6f045dbbf5041.
Report an issue: GitHub.