public static function find_by_subject($subject_type, $subject_id) { // cached already? this is important as we often have several modules referencing the same item $cache_key = "item:{$subject_type}:{$subject_id}"; $item = Cache::getValue($cache_key); if (!empty($item)) { return $item; } $r = Dal::query_one_assoc("SELECT * FROM {items} WHERE subject_type=? AND subject_id=?", array($subject_type, $subject_id)); if (!$r) { return NULL; } $item = new Item(); $item->load_from_row($r); Cache::setValue($cache_key, $item); return $item; }