diff --git a/classes/Model.php b/classes/Model.php index 2cc645b..28e17eb 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -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)) {