protected function cachedInstance() {
        $findInstance = function($id, $cache) use (&$findInstance) {
            self::selectIds($id, $ids);

            if (array_key_exists($id, $cache)) {
                return (empty($ids)) ?
                        $cache[$id] : $findInstance($id, $cache[$id]);
            }

            return null;
        };

        foreach ($this->cacheIds() as $id) {
            $instance = $findInstance($id, self::$cache);
            if ($instance != null) {
                return $instance;
            }
        }

        return null;
    }