We have understood the use of the S method in thinkphp, the F method is actually a subset of the S method, only for the simple data cache, and only support the file form, does not support the cache validity period, because the use of Php return method, so its efficiency is higher than the S method, So we also call it the fast caching method.
The F method is characterized by:
simple data caching;
File Form Preservation;
Load the cache using the PHP return Data mode;
Supports subdirectory caching and automatic creation;
Support to delete cache and bulk delete;
Write and read cache
- F(' data ',' test data ');
Copy Code
The default save starting path is Data_path (the constant is in the default configuration at Runtime_path. ' data/' below), that is, the generated file name is Data_path. ' data.php ' cache file.
Note: Make sure that your cache identity is unique and avoid data overwrite and conflicts.
The next time the cache data is read, use:
- $Data = F(' Data ');
Copy Code
We can use subdirectories to save, for example:
- F(' User/data ',$data); //Cache write
- F(' user/data '); //Read cache
Copy Code
The Data_path will be generated. ' user/data.php ' cache file, if the user subdirectory does not exist, it will be created automatically, or can support a multilevel subdirectory, for example:
- F(' Level1/level2/data ',$data);
Copy Code
If you need to specify the starting directory for the cache, you can do this in the following way:
- F(' data ',$data,temp_path);
Copy Code
When you get it, you need to use:
- F(' data ',',temp_path);
Copy Code Delete cache
Deleting the cache is also simple, using:
- F(' data ',NULL);
Copy Code
The second parameter passes in NULL, which means that the data cache that is identified is deleted.
Support for bulk deletion, especially for subdirectory caches, assuming we want to delete all cached data under the user subdirectory, you can use:
- F(' user/* ',NULL);
Copy Code
or delete using filter conditions, for example:
- F(' user/[^a]* ',NULL);
Original website: http://www.thinkphp.cn/document/312.html
thinkphp function: F method