use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
/**
* @Cache(cache="<put your prefix>", [key="<name of argument to
namespace AppCacheBundle\Service;
use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
class AppService
{
/**
* @Cache(cache="app_high_cpu", ttl=60)
*
* @return int
*/
public function getHighCPUOperation(): int
{
sleep(10); // 'Simulate a time consuming operation';
return 20;
}
}
use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
#[Cache(cache:'<put your prefix>', key:'<name of argument to
namespace AppCacheBundle\Service;
use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
class AppService
{
#[Cache(cache:'app_high_cpu', ttl: 60)]
public function getHighCPUOperation(): int
{
sleep(10); // 'Simulate a time consuming operation';
return 20;
}
}
namespace AppCacheBundle\Service;
use EmagTechLabs\AnnotationCacheBundle\Annotation\Cache;
class AppService
{
/**
* @Cache(cache="simple_time_consuming_operation_", ttl=60, storage="redis")
*
* @param int $a
* @param int $b
*
* @return int
*/
public function getSimpleTimeConsumingOperationValue(int $a, int $b): int
{
sleep(10); // 'Simulate a time consuming operation';
return $a + $b;
}
#[Cache(cache:'time_consuming_operation_', key: 'a,b', ttl: 3600, storage: 'redis')]
public function getTimeConsumingOperationValue(int $a, int $b): int
{
return $this->getTimeConsumingOperationValueWithReset($a, $b);
}
#[Cache(cache:'time_consuming_operation_', key: 'a,b', ttl: 3600, reset: true, storage: 'redis')]
public function getTimeConsumingOperationValueWithReset(int $a, int $b): int
{
sleep(10); // 'Simulate a time consuming operation';
return $a + $b;
}
}
// from controller
/** AppService $appService */
$appService->getTimeConsumingOperationValue(1, 2);
// from command
/** AppService $appService */
$appService->getTimeConsumingOperationValueWithReset(1, 2);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.