rewrite the cache logic