Updated to not store empty cache

Primary key queries should not be cached because the record may not exist today but could exist in the future and because the INSERT logic in PICKLES doesn't do any invalidation of the cache.
This commit is contained in:
Josh Sherman 2013-09-27 13:40:44 -04:00
parent 7ed930d278
commit 011f9b42b2

View file

@ -633,7 +633,24 @@ class Model extends Object
{
if (isset($cache_key))
{
$this->cache->set($cache_key, $passed_key ? $this->records : $this->records[0]);
if ($passed_key)
{
$cache_value = $this->records;
}
elseif (isset($this->records[0]))
{
$cache_value = $this->records[0];
}
// Only set the value for non-empty records. Caching
// values that are empty could be caused by querying
// records that don't exist at the moment, but could
// exist in the future. INSERTs do not do any sort of
// cache invalidation at this time.
if (isset($cache_value))
{
$this->cache->set($cache_key, $cache_value);
}
}
elseif (isset($cache_keys))
{