thinkphp function: F method

Source: Internet
Author: User
Tags delete cache

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
    1. 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:

    1. $Data = F(' Data ');
Copy Code

We can use subdirectories to save, for example:

    1. F(' User/data ',$data); //Cache write
    2. 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:

    1. 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:

    1. F(' data ',$data,temp_path);
Copy Code

When you get it, you need to use:

    1. F(' data ',',temp_path);
Copy Code Delete cache

Deleting the cache is also simple, using:

    1. 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:

    1. F(' user/* ',NULL);
Copy Code

or delete using filter conditions, for example:

      1. F(' user/[^a]* ',NULL);

Original website: http://www.thinkphp.cn/document/312.html

thinkphp function: F method

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.