added logic for cache