Permalink
Browse files

Refactors Model::_clearCache

- don't use mixed keys in $assoc array
- removes unnecessary strtolower on Inflector::underscore result
- return early
  • Loading branch information...
1 parent 99ec97b commit be61a5023f6052b7765bddfb3b29e52407d0df85 @Schlaefer Schlaefer committed Sep 28, 2013
Showing with 14 additions and 19 deletions.
  1. +14 −19 lib/Cake/Model/Model.php
@@ -3499,28 +3499,23 @@ public function onError() {
* @return boolean true on delete
*/
protected function _clearCache($type = null) {
- if ($type === null) {
- if (Configure::read('Cache.check') === true) {
- $pluralized = Inflector::pluralize($this->alias);
- $assoc[$this->alias] = strtolower($pluralized);
- $assoc[] = strtolower(Inflector::underscore($pluralized));
- foreach ($this->_associations as $association) {
- foreach ($this->$association as $associatedClass) {
- $className = $associatedClass['className'];
- if (!isset($assoc[$className])) {
- $pluralized = Inflector::pluralize($className);
- $assoc[$className] = strtolower($pluralized);
- $assoc[] = strtolower(Inflector::underscore($pluralized));
- }
- }
+ if ($type !== null || Configure::read('Cache.check') !== true) {
+ return;
+ }
+ $assoc[] = strtolower(Inflector::pluralize($this->alias));
+ $assoc[] = Inflector::underscore(Inflector::pluralize($this->alias));
+ foreach ($this->_associations as $association) {
+ foreach ($this->$association as $className) {
+ $pluralized = strtolower(Inflector::pluralize($className['className']));
+ if (!in_array($pluralized, $assoc)) {
+ $assoc[] = $pluralized;
+ $assoc[] = Inflector::underscore(Inflector::pluralize($className['className']));
}
- $assoc = array_unique($assoc);
- clearCache($assoc);
- return true;
}
- } else {
- //Will use for query cache deleting
}
+ $assoc = array_unique($assoc);
+ clearCache($assoc);
+ return true;
}
/**

0 comments on commit be61a50

Please sign in to comment.