From 011f9b42b289a2b57ab719741409d086f5aeb2f9 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Fri, 27 Sep 2013 13:40:44 -0400 Subject: [PATCH] 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. --- classes/Model.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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)) {