php 實現檔案快取函數代碼_PHP教程

來源:互聯網
上載者:User
  1. /**
  2. * 讀取或設定緩衝
  3. *
  4. * @access public
  5. * @param string $name 緩衝名稱
  6. * @param mixed $value 緩衝內容, null刪除緩衝
  7. * @param string $path 緩衝路徑
  8. * @return mixed
  9. */
  10. function cache($name, $value = , $path = )
  11. {
  12. return false; //調試階段, 不進行緩衝
  13. $path = empty($path) ? ROOT_PATH . /Runtime/Data/ : $path;
  14. $file = $path . $name . .php;
  15. if (empty($value)) {
  16. //緩衝不存在
  17. if (!is_file($file)) {
  18. return false;
  19. }
  20. // 刪除緩衝
  21. if (is_null($value)) {
  22. unlink($file);
  23. return true;
  24. }
  25. $data = include $file;
  26. return $data;
  27. }
  28. $value = var_export($value, true);
  29. $value = "";
  30. return file_put_contents($file, $value);
  31. }
  32. //函數調用
  33. cache(name, array(a, b, c)); //寫入緩衝 name為緩衝名稱, 後面那個數組是緩衝的內容
  34. cache(name); //讀取緩衝
  35. cache(name, null); //刪除緩衝
  36. ?>

http://www.bkjia.com/PHPjc/486194.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486194.htmlTechArticle?php /** * 讀取或設定緩衝 * * @access public * @param string $name 緩衝名稱 * @param mixed $value 緩衝內容, null刪除緩衝 * @param string $path 緩衝路徑 * @re...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.