cleverage/cache-process-bundle
## Getting Started
This package, **Cache Process Bundle**, simplifies process management and caching in Laravel/Symfony applications. To get started:
1. **Installation**: Require via Composer:
```bash
composer require cleverage/cache-process-bundle
use Cleverage\CacheProcessBundle\CacheProcess;
$cacheProcess = new CacheProcess('my_process_key', 3600); // Cache for 1 hour
$result = $cacheProcess->run(function() {
return Process::execute('php artisan my:long-running-task');
});
Leverage the bundle to cache the output of expensive processes:
$cacheProcess = new CacheProcess('report_generation', 86400); // Daily cache
$report = $cacheProcess->run(function() {
return ReportGenerator::generate();
});
Useful for caching results of queued jobs to avoid reprocessing:
public function handle()
{
$cacheProcess = new CacheProcess('job_' . $this->jobId, 3600);
$result = $cacheProcess->run(function() {
return $this->executeJobLogic();
});
}
For Symfony applications, integrate with console commands:
use Symfony\Component\Console\Command\Command;
use Cleverage\CacheProcessBundle\CacheProcess;
class MyCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$cacheProcess = new CacheProcess('command_result', 3600);
$result = $cacheProcess->run(function() {
return $this->runCommandLogic();
});
}
}
Use tags to invalidate caches programmatically:
$cacheProcess = new CacheProcess('data_fetch', 3600, ['user_data']);
$cacheProcess->invalidateTags(['user_data']); // Invalidate all tagged caches
php and symfony/* packages in composer.json:
"require": {
"php": "^8.2 || ^8.3 || ^8.4 || ^8.5",
"symfony/*": "^7.4 || ^8.0"
}
'process'). Use unique identifiers (e.g., 'user_123_report')..env (e.g., CACHE_DRIVER=redis).CacheProcess::isCached() to verify if a process is being served from cache:
if ($cacheProcess->isCached()) {
logger("Serving cached result");
}
3600 for hourly caches). Avoid overly long TTLs for frequently changing data.CacheProcessEvent).CacheProcess class in unit tests to simulate cached/missed scenarios:
$mockCacheProcess = $this->createMock(CacheProcess::class);
$mockCacheProcess->method('run')->willReturn('cached_result');
NO_UPDATE_NEEDED would **not** apply here due to the breaking changes and new features.
How can I help you explore Laravel packages today?