lundi 2 mai 2016

Laravel Facade Implementation

I am confused as to how to use the cache in Laravel.

I can either use the Cache facade and do something like -

use Cache;

public function someMethod(){

    Cache::remember('users', 60 , function() {

            return DB::table('users')->get();

    });

}

Or I could use something like this -

use Illuminate\Contracts\Cache\Repository;

protected $cache;

public function __construct(Repository $repository){

$this->cache    = $repository;

}

public function someMethod(){

       $this->cache->remember('users', 60 , function() {

            return DB::table('users')->get();

    });

}

Both will implement the same method remember from vendor/laravel/framework/src/Illuminate/Cache/Repository.php Repository class which implements vendor/laravel/framework/src/Illuminate/Contracts/Cache/Repository.php which I have included in the second method.

So can I conclude that both the approach are same or is there anything wrong with my implementation.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SIip0A
via IFTTT

Aucun commentaire:

Enregistrer un commentaire