PHP code example of telcolab / cacher

1. Go to this page and download the library: Download telcolab/cacher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

telcolab / cacher example snippets


composer 


namespace App;

use TelcoLAB\Cacher\Traits\Cacheable;
use Illuminate\Database\Eloquent\Model;
  
class Post extends Model
{
    use Cacheable;
    ...
}



namespace App\Http\Controllers;

use App\Post;

class PostController extends Controller
{
    public function index()
    {
         /**
         * This query will be cache to your cache driver.
         */
        $posts = Post::where('published', 1)->latest()->get();

        return view('news.index', [
            'news' => $posts,
        ]);
    }
    ...
}

/**
* Cache will expire after x minutes.
* @var int
*/
protected $cacheExpireAfer = 1440;

/**
* The query will be cached for 360 minutes.
*/
$hotPosts = App\Post::where([
  ['views', '>=', '360']
])->remember(360)->get();

/**
* The query will not be cached at all.
*/
$hotPosts = App\Post::where([
  ['views', '>=', '360']
])->dontRemember()->get();

/**
* The query will cached forever until the Post model is updated or flushed manually.
*/
$hotPosts = App\Post::where([
  ['views', '>=', '360']
])->rememberForever()->get();

/**
* Flush cache for Post model manually.
*/
$flushCache = App\Post::flush();

/**
* Flush cache automatically by updating the model.
*/
$updatePostAndClearCache = App\Post::first()->update([
    'title' => 'Hello World!'
]);