PHP code example of iqual / authenticated_cache_warmer
1. Go to this page and download the library: Download iqual/authenticated_cache_warmer 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/ */
iqual / authenticated_cache_warmer example snippets
use Drupal\authenticated_cache_warmer\CacheWarmerUrl;
// Set up data.
$route = 'entity.node.canonical';
$entity_ids = [1, 2];
$user_ids = [2, 3];
// Set up urls.
$urls = [];
foreach($user_ids as $user_id) {
foreach($entity_ids as $entity_id) {
$urls[] = CacheWarmerUrl::create($route, ['node' => $entity_id], $user_id);
}
}
// Run cache warming (use proper DI for service).
$cacheWarmer = \Drupal::service('authenticated_cache_warmer.cache_warmer');
$cacheWarmer->seturls($urls);
$cacheWarmer->warm();