Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the f method of thinkphp

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report