Php file cache function code _ PHP Tutorial

Source: Internet
Author: User
Php implements the file cache function code .? Php *** READ or set cache ** @ accesspublic * @ paramstring $ name cache name * @ parammixed $ value cached content, null delete cache * @ paramstring $ path cache path * @ re

  1. /**
  2. * Read or set cache
  3. *
  4. * @ Access public
  5. * @ Param string $ name cache name
  6. * @ Param mixed $ value: cached content. null: deletes the cache.
  7. * @ Param string $ path: cache path
  8. * @ Return mixed
  9. */
  10. Function cache ($ name, $ value =, $ path =)
  11. {
  12. Return false; // In The debugging stage, no cache is performed.
  13. $ Path = empty ($ path )? ROOT_PATH./Runtime/Data/: $ path;
  14. $ File = $ path. $ name.. php;
  15. If (empty ($ value )){
  16. // The cache does not exist.
  17. If (! Is_file ($ file )){
  18. Return false;
  19. }
  20. // Delete cache
  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. // Function call
  33. Cache (name, array (a, B, c); // write the cache name as the cache name, and the following array is the cached content
  34. Cache (name); // read the cache
  35. Cache (name, null); // deletes the cache
  36. ?>


Http://www.bkjia.com/PHPjc/486194.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486194.htmlTechArticle? Php/*** READ or set cache ** @ access public * @ param string $ name cache name * @ param mixed $ value cached content, null delete cache * @ param string $ path cache path * @ re...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.