public static function byKey($_key, $_noRemove = false) { $values = array('key' => $_key); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cache WHERE `key`=:key'; $cache = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__); if (!is_object($cache)) { $cache = new self(); $cache->setKey($_key); $cache->setDatetime(date('Y-m-d H:i:s')); $cache->_hasExpired = true; } else { if (!$_noRemove && $cache->hasExpired()) { $cache->remove(); } } return $cache; }