PHP code example of blackbird / module-cache-warmer
1. Go to this page and download the library: Download blackbird/module-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/ */
blackbird / module-cache-warmer example snippets
namespace YourVendor\YourModule\Model\Collector;
use Blackbird\CacheWarmer\Api\UrlCollectorInterface;
use Magento\Store\Api\Data\StoreInterface;
class YourCustomCollector implements UrlCollectorInterface
{
/**
* @inheritDoc
*/
public function collectUrls(array $stores): array
{
$urls = [];
// Your custom logic to collect URLs
return $urls;
}
}
namespace YourVendor\YourModule\Model\CollectorType;
use Blackbird\CacheWarmer\Api\CollectorTypeProviderInterface;
use YourVendor\YourModule\Model\Collector\YourCustomCollector;
class Provider implements CollectorTypeProviderInterface
{
/**
* @param YourCustomCollector $customCollector
*/
public function __construct(
protected YourCustomCollector $customCollector
) {
}
/**
* @inheritDoc
*/
public function getCollectorTypes(): array
{
return [
'your_custom_type' => [
'sort_order' => 30, // Higher than existing types
'class' => $this->customCollector,
'label' => __('Your Custom Type')
]
];
}
}
namespace YourVendor\YourModule\Model\EntityUrlProvider;
use Blackbird\CacheWarmer\Api\EntityUrlProviderInterface;
use Blackbird\CacheWarmer\Api\Data\EntityQueueInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class YourCustomEntityUrlProvider implements EntityUrlProviderInterface
{
/**
* Get the URL for an entity
*
* @param int $entityId The ID of the entity
* @param int $storeId The store ID
* @return string The URL of the entity
* @throws NoSuchEntityException If the entity does not exist
*/
public function getUrl(int $entityId, int $storeId): string
{
// Your custom logic to get the URL for the entity
return $url;
}
/**
* Check if this provider supports the given entity type
*
* @param string $entityType The entity type
* @return bool True if this provider supports the entity type, false otherwise
*/
public function supports(string $entityType): bool
{
return $entityType === 'your_custom_entity_type';
}
}