Modify the F method of ThinkPHP3.2

Source: Internet
Author: User
Tags delete cache
Provides various official and user-released code examples. For code reference, you are welcome to learn how to modify the F method of ThinkPHP3.2.
F of ThinkPHP3.2 stores data in serialization mode, because the file name stored in F method is known.
May cause some data leakage. Therefore, modify the F method here.

Directly replace the F method of TP. Function F ($ name, $ value = '', $ path = DATA_PATH ){
Static $ _ cache = array ();
$ Filename = $ path. $ name. '. php ';
If (''! ==$ Value ){
If (is_null ($ value )){
// Delete Cache
Return false! = Strpos ($ name ,'*')? Array_map ("unlink", glob ($ filename): unlink ($ filename );
} Else {
// Cache data
$ Dir = dirname ($ filename );
// Create if the directory does not exist
If (! Is_dir ($ dir ))
Mkdir ($ dir, 0755, true );
$ _ Cache [$ name] = $ value;
Return file_put_contents ($ filename, strip_whitespace (" "));
}
}
If (isset ($ _ cache [$ name])
Return $ _ cache [$ name];
// Obtain cache data
If (is_file ($ filename )){
$ Value = include $ filename;
$ _ Cache [$ name] = $ value;
} Else {
$ Value = false;
}
Return $ value;
}
QQ chat group: 17540504

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.