1
0

BxDolCacheFileHtml.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolCacheFile');
  9. class BxDolCacheFileHtml extends BxDolCacheFile {
  10. /**
  11. * constructor
  12. */
  13. function BxDolCacheFileHtml() {
  14. parent::BxDolCacheFile();
  15. }
  16. /**
  17. * Get all data from the cache file.
  18. *
  19. * @param string $sKey - file name
  20. * @param int $iTTL - time to live
  21. * @return the data is got from cache.
  22. */
  23. function getData($sKey, $iTTL = false) {
  24. if(!file_exists($this->sPath . $sKey))
  25. return null;
  26. if ($iTTL > 0 && $this->_removeFileIfTtlExpired ($this->sPath . $sKey, $iTTL))
  27. return null;
  28. return file_get_contents($this->sPath . $sKey);
  29. }
  30. /**
  31. * Get full path to cache file
  32. */
  33. function getDataFilePath($sKey, $iTTL = false) {
  34. if (!file_exists($this->sPath . $sKey))
  35. return null;
  36. if ($iTTL > 0 && $this->_removeFileIfTtlExpired ($this->sPath . $sKey, $iTTL))
  37. return null;
  38. return $this->sPath . $sKey;
  39. }
  40. /**
  41. * Save all data in cache file.
  42. *
  43. * @param string $sKey - file name
  44. * @param mixed $mixedData - the data to be cached in the file
  45. * @param int $iTTL - time to live
  46. * @return boolean result of operation.
  47. */
  48. function setData($sKey, $mixedData, $iTTL = false) {
  49. if(file_exists($this->sPath . $sKey) && !is_writable($this->sPath . $sKey))
  50. return false;
  51. if(!($rHandler = fopen($this->sPath . $sKey, 'w')))
  52. return false;
  53. fwrite($rHandler, $mixedData);
  54. fclose($rHandler);
  55. @chmod($this->sPath . $sKey, 0666);
  56. return true;
  57. }
  58. }