ThinkPHP Function details: F method

Source: Internet
Author: User
We have understood the usage of the S method in ThinkPHP. The F method is actually a subset of the S method. it is only used for simple data caching and only supports file formats, but does not support cache validity periods, because PHP is used to return data, it is more efficient than the S method. Therefore, it is also called the quick cache method. We have understood the usage of the S method in ThinkPHP. The F method is actually a subset of the S method. it is only used for simple data caching and only supports file formats, but does not support cache validity periods, because PHP is used to return data, it is more efficient than the S method. Therefore, it is also called the quick cache method.
The F method has the following features:
Simple data cache;
Save as a file;
Use PHP to return data to load the cache;
Sub-directory caching and automatic creation are supported;
Supports deletion of cache and batch deletion;

Write and read cache
  1. F ('data', 'Test data ');
The default save Start Path of the Copy code is DATA_PATH (the constant is in RUNTIME_PATH by default. under 'data/'), that is, the file name is generated as DATA_PATH. 'data. php.
Note: Make sure that your cache ID is unique to avoid data overwrites and conflicts.
Next time you read the cached data, use:
  1. $ Data = F ('data ');
Copy the code and save it in sub-directories. for example:
  1. F ('user/data', $ data); // cache write
  2. F ('user/data'); // read the cache
Copy the code to generate the DATA_PATH. 'user/data. php' cache file. if the user sub-directory does not exist, it will be automatically created. you can also support multi-level sub-directories, for example:
  1. F ('level1/level2/data', $ data );
If you need to specify the starting Directory of the cache to copy the code, you can use the following method:
  1. F ('data', $ data, TEMP_PATH );
Use the following command to copy the code:
  1. F ('data', '', TEMP_PATH );
It is also easy to copy the code to delete the cache and delete the cache. use:
  1. F ('data', NULL );
If the second parameter of the copied code is NULL, the data cache marked as data is deleted.
Batch deletion is supported, especially for sub-directory caching. if you want to delete all the cached data under the user sub-directory, you can use:
  1. F ('user/* ', NULL );
Copy the code or use a filter condition to delete it. for example:
  1. F ('user/[^ a] * ', NULL );
Copy code

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.