PHP code example of shopwwi / laravel-cache

1. Go to this page and download the library: Download shopwwi/laravel-cache 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/ */

    

shopwwi / laravel-cache example snippets




namespace app\controller;

use Shopwwi\LaravelCache\Cache;

class UserController extends Controller
{
    /**
     * 显示应用程序的所有用户的列表。
     *
     * @return Response
     */
    public function index()
    {
        $value = Cache::get('key');

        //
    }
}



$value = Cache::store('file')->get('foo');

Cache::store('redis')->put('bar', 'baz', 600); // 10 Minutes



$value = Cache::get('key');

$value = Cache::get('key', 'default');



$value = Cache::get('key', function () {
    return Db::table(...)->get();
});


if (Cache::has('key')) {
    //
}


Cache::increment('key');
Cache::increment('key', $amount);
Cache::decrement('key');
Cache::decrement('key', $amount);



$value = Cache::remember('users', $seconds, function () {
    return Db::table('users')->get();
});



$value = Cache::rememberForever('users', function () {
    return Db::table('users')->get();
});



$value = Cache::pull('key');



Cache::put('key', 'value', $seconds = 10);



Cache::put('key', 'value');



Cache::put('key', 'value', now()->addMinutes(10));



Cache::add('key', 'value', $seconds);



Cache::forever('key', 'value');



Cache::forget('key');



Cache::put('key', 'value', 0);

Cache::put('key', 'value', -5);



Cache::flush();



Cache::tags(['people', 'artists'])->put('John', $john, $seconds);

Cache::tags(['people', 'authors'])->put('Anne', $anne, $seconds);



$john = Cache::tags(['people', 'artists'])->get('John');

$anne = Cache::tags(['people', 'authors'])->get('Anne');



Cache::tags(['people', 'authors'])->flush();



Cache::tags('authors')->flush();


//路径 config/laravelcache.php