CacheInstructions.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace dokuwiki\Cache;
  3. /**
  4. * Caching of parser instructions
  5. */
  6. class CacheInstructions extends \dokuwiki\Cache\CacheParser
  7. {
  8. /**
  9. * @param string $id page id
  10. * @param string $file source file for cache
  11. */
  12. public function __construct($id, $file)
  13. {
  14. parent::__construct($id, $file, 'i');
  15. }
  16. /**
  17. * retrieve the cached data
  18. *
  19. * @param bool $clean true to clean line endings, false to leave line endings alone
  20. * @return array cache contents
  21. */
  22. public function retrieveCache($clean = true)
  23. {
  24. $contents = io_readFile($this->cache, false);
  25. return !empty($contents) ? unserialize($contents) : array();
  26. }
  27. /**
  28. * cache $instructions
  29. *
  30. * @param array $instructions the instruction to be cached
  31. * @return bool true on success, false otherwise
  32. */
  33. public function storeCache($instructions)
  34. {
  35. if ($this->_nocache) {
  36. return false;
  37. }
  38. return io_saveFile($this->cache, serialize($instructions));
  39. }
  40. }