Added a check on result length before saving to cache
Made some major code refactoring
Added a new method to delete from the cache
Fixed formatting
Renamed the delete function into clear