-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed as not planned
Description
Description
It happens a lot to use class property as a caching method.
For example :
class OrderStatus {
protected $statusLabels = [];
public function getStatusLabel(int $statusCode) {
if(!isset($this->statusLabels[$statusCode])) {
$this->statusLabels[$statusCode] = $this->loadStatusLabelFromDatabase($statusCode);
}
return $this->statusLabels[$statusCode];
}
}
Would be great to have some new syntax to do this behind the scene :
class OrderStatus {
public cacheable function getStatusLabel(int $statusCode) {
return $this->loadStatusLabelFromDatabase($statusCode);
}
}
Of course, some rules should exists, like a function cannot be cached if some parameters are not typed or not a basic type, or dynamic, since this feature requires to serialize method parameters.
What do you think ?
ju1ius and mvorisek