shiny's avatar

Sessions and cache being used when both set as disabled

Trying to access POST endpoint to add a user to a table in API when validation fails and Lumen seemingly attempts to create a Session and use cache, when they have been commented out in app.php. What follows is the relevant error dump...

InvalidArgumentException in CacheManager.php line 90:
Cache store [apc] is not defined.
in CacheManager.php line 90
at CacheManager->resolve('apc') in CacheManager.php line 77
at CacheManager->get('apc') in CacheManager.php line 55
at CacheManager->store('apc') in CacheManager.php line 66
at CacheManager->driver('apc') in SessionManager.php line 155
at SessionManager->createCacheHandler('apc') in SessionManager.php line 143
at SessionManager->createCacheBased('apc') in SessionManager.php line 98
at SessionManager->createApcDriver() in Manager.php line 87
at Manager->createDriver('apc') in Manager.php line 63
at Manager->driver() in Manager.php line 137
at Manager->__call('previousUrl', array()) in ValidatesRequests.php line 79
at SessionManager->previousUrl() in ValidatesRequests.php line 79
at Controller->getRedirectUrl() in ValidatesRequests.php line 56
at Controller->buildFailedValidationResponse(object(R
Is anyone able to tell me why Sessions and caching are being activate and how to fix this problem?
0 likes
9 replies
martink8's avatar

How did you disable cache in app.php?

In your .env file you probably set your CACHE_DRIVER to something you didn't set up. Just set it to CACHE_DRIVER=file if you will not be using any caching mechanism.

1 like
alenabdula's avatar

I had this issue yesterday and setting the session driver to file worked for me.

shiny's avatar

@martink8, @alenabdula - Where in the docs do you find this information? I read through http://lumen.laravel.com/docs/cache#configuration and it isn't there.

As how I disabled it I followed some instructions to leave the following lines uncommented in app.php

// $app->middleware([
//     // Illuminate\Cookie\Middleware\EncryptCookies::class,
//     // Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
//     // Illuminate\Session\Middleware\StartSession::class,
//     // Illuminate\View\Middleware\ShareErrorsFromSession::class,
//     // Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
// ]);
shiny's avatar

I changed the .env entries to the following...

CACHE_DRIVER=file
SESSION_DRIVER=file

And I get the following error message using the postman extension for Chrome to send a POST form request to test an endpoint

MethodNotAllowedHttpException in Application.php line 1188:
in Application.php line 1188
at Application->handleDispatcherResponse(array('2', array('GET'))) in Application.php line 1143
at Application->Laravel\Lumen\{closure}() in Application.php line 1370
at Application->sendThroughPipeline(array(), object(Closure)) in Application.php line 1144
at Application->dispatch(null) in Application.php line 1084
at Application->run() in index.php line 28

Any ideas as to the source of this error?

martink8's avatar

This is the session middleware. The Cache still gets started up (you can't disable it) and since you have it set to something else than file you need to configure it. I don't think its anywhere in the docs.

Copy the routes.php and the appropriate controller if you are using one. I need more information :)

shiny's avatar

@martink8 - I meant where in the docs is CACHE_DRIVER=file explained? Because having to learn how to get Lumen working by posting questions to the forums, rather than the online documentation is too costly in time.

from routes.php

$app->group(['prefix' => 'api/v1','namespace' => 'App\Http\Controllers'], function($app) {
    $app->get('accounts', ['as'=>'accounts', 'uses'=>'AccountController@accounts']);
    $app->get('accounts/{id}', ['as'=>'get_account', 'uses'=>'AccountController@getAccount']);
    $app->post('accounts', ['as'=>'accounts', 'uses'=>'AccountController@createAccount']);
    $app->put('accounts/{id}', ['as'=>'accounts', 'uses'=>'AccountController@updateAccount']);
    $app->delete('accounts/{id}', ['as'=>'accounts', 'uses'=>'AccountController@deleteAccount']);
});

and from AccountController.php

    public function createAccount(Request $request)
    {
        $this->validateRequest($request);
        $Account = Account::create($request->all());
    return response()->json($Account);
}
martink8's avatar
Level 5

Oh I am sorry, didn't get ya there. It's explained in the docs - http://lumen.laravel.com/docs/cache#configuration - on how to use redis, memcached and database.

Although the file part is left out. It is mentioned in the Laravel docs: http://laravel.com/docs/5.1/cache#configuration

I think the default option here should be file, but for whatever reason it's set to memcached. No idea why.

Everything seems ok. Try using dd() before doing anything else in the controller and see what happens or debugging a little :)

Please or to participate in this conversation.