Caching issue


I am using Memcache to cache content in my Yii2 application. It works fine while using the below code inside the controller for caching query data, but for some reason I try to cache data in widgets or main.php layout file using below code it is creating file cache in running/debug folder instead of using Memcache.

$Data = \Yii::$app->cache->get($CacheName);

\Yii::$app->cache->set($CacheName, $Data, 3600);