Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the f method of thinkphp

Shulou Source: shulou.com Published: 2022-06-02 05:40:39 09月22日 Update

The editor will share with you how to use the f method of thinkphp. I hope you will get something after reading this article. Let's discuss it together.

The thinkphp f method is a subset of the S method, which is only used for simple data caching and can only support file form, not cache validity, and uses syntax such as "F ('data','test data');".

This article operating environment: Windows7 system, thinkphp v5.1, Dell G3 computer.

We have understood the usage of S method in ThinkPHP. F method is actually a subset of S method, which is only used for simple data caching, and can only support file form, not cache validity. Because the PHP return method is used, it is more efficient than S method, so we also call it fast caching method.

The characteristics of F method are:

Simple data caching

Save in file form

Load cache by returning data from PHP

Support for subdirectory caching and automatic creation

Support for cache deletion and batch deletion

Write and read cach

F ('data','test data')

The default save starting path is DATA_PATH (this constant is located under RUNTIME_PATH.'Data/' by default), which means that a cache file with the file name DATA_PATH.'data.php' is generated.

Note: make sure your cache identity is unique to avoid data overwriting and conflicts.

The next time you read the cached data, use:

$Data = F ('data')

We can save it as a subdirectory, for example:

F ('user/data',$data); / / cache write F (' user/data'); / / read cache

A DATA_PATH.'user/data.php' cache file is generated, which is automatically created if the user subdirectory does not exist, or multi-level subdirectories can be supported, such as:

F ('level1/level2/data',$data)

If you need to specify the starting directory of the cache, you can use the following ways:

F ('data',$data,TEMP_PATH)

When you get it, you need to use:

F ('data','',TEMP_PATH)

Delete cach

Deleting the cache is also easy, using:

F ('data',NULL)

When the second parameter is passed in NULL, the data cache identified as data is deleted.

Batch deletion is supported, especially in the case of caching for subdirectories. If we want to delete all cached data under the usersubdirectory, we can use:

F ('user/*',NULL)

Or use filter criteria to delete, for example:

F ('user/ [^ a] *', NULL); after reading this article, I believe you have some understanding of "how to use the f method of thinkphp". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Tags: Cache method data support subitem subdirectory file mode function form valid subset time validity identity article face generate start that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Microsoft Apple Shulou Technology