updated the cache logic. added debug env flag to cmd.