Permalink
Browse files

performance improvements in Model::_clearCache

- don't empty cache twice if pluralized name is identical to underscored
- refactors for fewer function calls
  • Loading branch information...
1 parent 355e2ef commit 99ec97bd19cddcec75b4bf9310a9a4d345162d7b @Schlaefer Schlaefer committed Sep 27, 2013
Showing with 11 additions and 8 deletions.
  1. +11 −8 lib/Cake/Model/Model.php
View
@@ -3501,17 +3501,20 @@ public function onError() {
protected function _clearCache($type = null) {
if ($type === null) {
if (Configure::read('Cache.check') === true) {
- $assoc[] = strtolower(Inflector::pluralize($this->alias));
- $assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($this->alias)));
- foreach ($this->_associations as $key => $association) {
- foreach ($this->$association as $key => $className) {
- $check = strtolower(Inflector::pluralize($className['className']));
- if (!in_array($check, $assoc)) {
- $assoc[] = strtolower(Inflector::pluralize($className['className']));
- $assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($className['className'])));
+ $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));
}
}
}
+ $assoc = array_unique($assoc);
clearCache($assoc);
return true;
}

0 comments on commit 99ec97b

Please sign in to comment.