You probably should move this up above the previous caching statement as your currently calling JFactory::getApplication twice in two lines!