Bilal Rabbi
Bilal Rabbi

Reputation: 1840

Laravel 5 how to use memcache

I have installed memcache on my linux server. when i try to use it from core php file or codeigniter framework it is working.

        $memcache = new Memcache;
        $memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
        $memcache->set('a', 'test');
        echo $memcache->get('a');

Same code is not working in laravel controller. I tried using

use Cache \Cache and use \Memcached  (at the top )

i also tried memcached but it is still working. i am getting following error

Class 'App\Http\Controllers\Memcached' not found

Help please..

Upvotes: 2

Views: 3274

Answers (1)

Bilal Rabbi
Bilal Rabbi

Reputation: 1840

Thanks for help guys. I install memcached on my server. Update .env file to CACHE_DRIVER=memcached In controller file i added use Memcached; and use below code and it worked

    $memcache = new Memcached;
    $memcache ->addServer('localhost', 11211);
    $memcache->set('a', 'tet');
    echo $memcache->get('a');
    exit;

Thanks

Upvotes: 2

Related Questions