1. Go to this page and download the library: Download generoi/sage-cachetags 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/ */
namespace App\View\Composers;
use Genero\Sage\CacheTags\Concerns\ComposerCacheTags;
use Genero\Sage\CacheTags\Tags\CoreTags;
use Roots\Acorn\View\Composer;
use Illuminate\View\View;
class ContentSingle extends Composer
{
use ComposerCacheTags;
protected static $views = [
'partials.content-single',
];
/**
* @return array
*/
public function with()
{
$post = get_post();
return [
'post' => $post,
'date' => $this->date($post),
'authors' => $this->authors($post),
'excerpt' => $this->excerpt($post),
'related' => $this->related($post),
'categories' => $this->categories($post),
];
}
public function cacheTags(View $view): array
{
return [
...CoreTags::posts($view->post),
...CoreTags::terms($view->categories),
...CoreTags::query($this->related())
];
}
}
namespace App\Blocks;
use Genero\Sage\CacheTags\Tags\CoreTags;
use Genero\Sage\CacheTags\Concerns\BlockCacheTags;
class ArticleList extends Block
{
use BlockCacheTags;
public $name = 'Article List';
public $slug = 'article-list';
public function cacheTags(): array
{
$query = $this->buildQuery();
return [
...CoreTags::archive('post'),
...CoreTags::query($query),
];
}
}
// Tag content
app(CacheTags::class)->add(['custom-tag']);
// Clear it whenever you want
\add_action('custom/update', fn() => app(CacheTags::class)->clear(['custom-tag']));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.