Added a few defensive checks and fixed a bug where update wasn't being added to cache.