BxDolCacheFileHtml.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. class BxDolCacheFileHtml extends BxDolCacheFile
  10. {
  11. /**
  12. * Get all data from the cache file.
  13. *
  14. * @param string $sKey - file name
  15. * @param int $iTTL - time to live
  16. * @return the data is got from cache.
  17. */
  18. function getData($sKey, $iTTL = false)
  19. {
  20. if(!file_exists($this->sPath . $sKey))
  21. return null;
  22. if ($iTTL > 0 && $this->_removeFileIfTtlExpired ($this->sPath . $sKey, $iTTL))
  23. return null;
  24. return file_get_contents($this->sPath . $sKey);
  25. }
  26. /**
  27. * Get full path to cache file
  28. */
  29. function getDataFilePath($sKey, $iTTL = false)
  30. {
  31. if (!file_exists($this->sPath . $sKey))
  32. return null;
  33. if ($iTTL > 0 && $this->_removeFileIfTtlExpired ($this->sPath . $sKey, $iTTL))
  34. return null;
  35. return $this->sPath . $sKey;
  36. }
  37. /**
  38. * Save all data in cache file.
  39. *
  40. * @param string $sKey - file name
  41. * @param mixed $mixedData - the data to be cached in the file
  42. * @param int $iTTL - time to live
  43. * @return boolean result of operation.
  44. */
  45. function setData($sKey, $mixedData, $iTTL = false)
  46. {
  47. if(file_exists($this->sPath . $sKey) && !is_writable($this->sPath . $sKey))
  48. return false;
  49. if(!($rHandler = fopen($this->sPath . $sKey, 'w')))
  50. return false;
  51. fwrite($rHandler, $mixedData);
  52. fclose($rHandler);
  53. @chmod($this->sPath . $sKey, 0666);
  54. return true;
  55. }
  56. }
  57. /** @} */