/** * Flush the cached results for all relations (has_one, has_many, many_many) */ public function flushCache() { if($this->class == 'DataObject') { DataObject::$cache_get_one = array(); return; } if(!self::$cache_get_one) return; $classes = ClassInfo::ancestry($this->class); foreach($classes as $class) { if(isset(self::$cache_get_one[$class])) unset(self::$cache_get_one[$class]); } $this->extend('flushCache'); $this->componentCache = array(); }
/** * Flush the cached results for get_one() */ public function flushCache() { if ($this->class == 'DataObject') { DataObject::$cache_get_one = array(); return; } $classes = ClassInfo::ancestry($this->class); foreach ($classes as $class) { // If someone else has called get_one and flushCache() is called, then that object will be destroyed. // Not very friendly. We need a better way of dealing with PHP's garbage collection limitations. // Until then, this line is being commented out. // if(DataObject::$cache_get_one[$class]) foreach(DataObject::$cache_get_one[$class] as $obj) if($obj) $obj->destroy(); DataObject::$cache_get_one[$class] = null; } }
/** * Reset internal caches, for example after test runs */ static function reset() { self::$cache_get_one = array(); self::$cache_buildSQL_query = array(); }
static function flush_and_destroy_cache() { if (self::$cache_get_one) { foreach (self::$cache_get_one as $class => $items) { if (is_array($items)) { foreach ($items as $item) { if ($item) { $item->destroy(); } } } } } self::$cache_get_one = array(); }