BxDolCacheFileHtml.php 1.8 KB

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