Moved cache cleaning code near the begin of functions. Sometimes it wasnt' executed due to function ending. MDL-7196
Moved cache cleaning code near the begin of functions. Sometimes
it wasnt' executed due to function ending. MDL-7196

Merged from MOODLE_17_STABLE

dilawar/moodle