Refactor cache functions for get method
Fix "key not found" bug for set method