1. Go to this page and download the library: Download mostafaznv/laracache 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/ */
mostafaznv / laracache example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Mostafaznv\LaraCache\Traits\LaraCache;
class Article extends Model
{
use LaraCache;
/**
* Define Cache Entities Entities
*
* @return CacheEntity[]
*/
public static function cacheEntities(): array
{
return [
CacheEntity::make('list.forever')
->cache(function() {
return Article::query()->latest()->get();
}),
CacheEntity::make('latest')
->validForRestOfDay()
->cache(function() {
return Article::query()->latest()->first();
})
];
}
}
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
$cache = Article::cache()->get('latest');
// or
$cache = LaraCache::retrieve(Article::class, 'latest');
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->disable();
// or
LaraCache::disable(Article::class);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->enable();
// or
LaraCache::enable(Article::class);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->update('latest');
// or
LaraCache::update(Article::class, 'latest');
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->updateAll();
// or
LaraCache::updateAll(Article::class);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
LaraCache::updateAll();
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->delete('latest');
// or
LaraCache::delete(Article::class, 'latest');
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->delete('latest', true);
// or
LaraCache::delete(Article::class, 'latest', true);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->deleteAll();
// or
LaraCache::deleteAll(Article::class);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
Article::cache()->deleteAll(true);
// or
LaraCache::deleteAll(Article::class, true);
use App\Models\Article;
use Mostafaznv\LaraCache\Facades\LaraCache;
LaraCache::deleteAll();
// forever
LaraCache::deleteAll(forever: true);