Home >Backend Development >PHP Tutorial >Dynamic caching (S method) and fast caching (F method) in ThinkPHP, thinkphp_PHP tutorial

Dynamic caching (S method) and fast caching (F method) in ThinkPHP, thinkphp_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:06:43805browse

Dynamic caching (S method) and fast caching (F method) in ThinkPHP, thinkphp

The default caching method of the system is to use File mode caching, we can use it in the project configuration file Define other caching methods inside, for example, modify the default caching method to Xcache (of course, your environment needs to support Regarding the file problem, ThinkPHP also provides a solution by enabling hash subdirectory caching.

'DATA_CACHE_SUBDIR'=>true

You can also set the level of the hash directory, such as

'DATA_PATH_LEVEL'=>2

You can automatically create multi-level subdirectories for caching based on the hash of the cache identifier.

The S method supports cache validity period. In many cases, we may not need the concept of validity period, or using file mode caching can meet the requirements, so the system also provides a quick cache specifically for file mode. Cache method F method. The F method can only be used to cache simple data types, and does not support validity periods and cache objects . Use the following:

//Quickly cache Data data, which is saved under the DATA_PATH directory by default
F ('data',$data);
//Quickly cache Data data and save it to the specified directory
F('data',$data,TEMP_PATH);
F('user/data', $data);
//Delete cached data
F('data',null);
//Get cached data
$data=F('data');

Configuration file config.php

//Dynamic cache, the cache file exists in RuntimeTemp
'DATA_CACHE_TYPE'=>'file',
'DATA_CACHE_TIME'=>'3600',
//'DATA_CACHE_SUBDIR'=>true,//Open subdirectory
//'DATA_CACHE_LEVEL'=>3,//Set the level of subdirectory

Action file:

Function view(){
                                                                                                                    Xcache',array('expire'=>60));
//$cache->set('name','value');or $cache->name='value';
             //$value=$cache->get('name'); or $value=$cache->name;
                 //$cache->rm('name'); or unset($ cache->name);
                                                                                                                                                                                                                                                                                         );
                                                                                 > S('list',$list,3600);
echo 'This is a file read directly from the database';
dump($list);
}else{
echo ' This is the cache file';
                                                         dump($value); 🎜>
After refreshing again, the picture is as follows:







http://www.bkjia.com/PHPjc/1064068.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/1064068.html

TechArticleDynamic caching (S method) and fast caching (F method) in ThinkPHP, thinkphp_PHP tutorial
Dynamic caching (S method) and fast caching (F method) in ThinkPHP, the default caching method of thinkphp system is Using File mode caching, we can define it in the project configuration file...


Dynamic caching (S method) and fast caching (F method) in ThinkPHP, thinkphp_PHP tutorial

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn