| 1 | <?php |
||
| 12 | trait CanCache |
||
| 13 | { |
||
| 14 | use HasCacheStore; |
||
| 15 | |||
| 16 | protected $needsCaching = false; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param null $needCaching |
||
| 20 | * @return bool |
||
| 21 | */ |
||
| 22 | public function needsCaching($needCaching = null): bool |
||
| 29 | |||
| 30 | protected function checkSaveCache() |
||
| 38 | |||
| 39 | abstract function generateCacheData(); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param null $key |
||
| 43 | * @return mixed|null |
||
| 44 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
| 45 | */ |
||
| 46 | protected function getDataFromCache($key = null) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param $data |
||
| 53 | * @param null $key |
||
| 54 | * @noinspection PhpDocMissingThrowsInspection |
||
| 55 | */ |
||
| 56 | protected function saveDataToCache($data, $key = null) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param $key |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | protected function dataCacheKey($key= null) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param null $key |
||
| 76 | * @return DateInterval |
||
| 77 | */ |
||
| 78 | protected function dataCacheTtl($key= null) |
||
| 82 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.