cache
Hi, How can we set cache param? This is how I enter it in the config array and get error. Warning: foreach() argument must be of type array|object, int given in c:\xampp\htdocs....\ vendor\izniburak\router\src\Router.php on line 271
[
'base_folder' => 'public/',
'main_method' => 'index',
'paths' => [
'controllers' => 'app/controllers',
'middlewares' => 'app/middlewares'
],
'namespaces' => [
'controllers' => 'app\controllers',
'middlewares' => 'app\middlewares'
],
'debug' => true,
'cache' => 'cache/route/cache.php'
];
Hi, Could you please share your routes you set?
@izniburak
use Buki\Router\Router;
use app\controllers\HomeController;
use app\controllers\CharacterController;
$routes = new Router(
[
'base_folder' => 'public/',
'main_method' => 'index',
'paths' => [
'controllers' => 'app/controllers',
'middlewares' => 'app/middlewares'
],
'namespaces' => [
'controllers' => 'app\controllers',
'middlewares' => 'app\middlewares'
],
'debug' => true,
'cache' => 'cache/route/cache.php'
]);
$routes->get('/', [HomeController::class, 'index'],['name' => 'home.index']);
$routes->get('/character/:id', [CharacterController::class, 'index'],['name' => 'character.index']);
$routes->run();
Did you use cache method for storing your routes? Example:
$routes->cache();
I tried similar scenario, but I couldn't get any error. It seems that everything's okay.
@izniburak
After using $routes->cache(), it still gives the same error Uncaught TypeError: Buki\Router\Router::getRoutes(): Return value must be of type array, int in izniburak\router\src\Router.php on line 470
it return int 1 in loadCache() method line on line 694 ($this->routes = require_once $this->cacheFile;)
But when I use Cache() method (copy and past method body) outside Buki\Router\Router class , the cache file fills up.
Could you delete your cache file and try again to cache your routes again? Probably, you have an issue about cached routes file. After the loading cached routes process, it returns a wrong value because of the old cached file.