Php function code for writing and reading cached files,

Source: Internet
Author: User

Php function code for writing and reading cached files,

I. Write result cache files

/*** Write result cache file ** @ params string $ cache_name * @ params string $ caches ** @ return */function write_static_cache ($ cache_name, $ caches) {if (DEBUG_MODE & 2) = 2) {return false;} $ cache_file_path = ROOT_PATH. '/temp/static_caches /'. $ cache_name. '. php'; $ content = "<? Php \ r \ n "; $ content. = "\ $ data = ". var_export ($ caches, true ). "; \ r \ n"; $ content. = "?> "; File_put_contents ($ cache_file_path, $ content, LOCK_EX );}

Ii. Read result cache files

/*** Read result cache file ** @ params string $ cache_name ** @ return array $ data */function read_static_cache ($ cache_name) {if (DEBUG_MODE & 2) = 2) {return false;} static $ result = array (); if (! Empty ($ result [$ cache_name]) {return $ result [$ cache_name];} $ cache_file_path = ROOT_PATH. '/temp/static_caches /'. $ cache_name. '. php '; if (file_exists ($ cache_file_path) {include_once ($ cache_file_path); $ result [$ cache_name] = $ data; return $ result [$ cache_name];} else {return false ;}}

The above is the function code that php writes to the cache file and reads the content of the cache file. For more information, see.

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.