Updating the code of avoid caching "null" result

Updating the code of avoid caching "null" result