Home  >  Article  >  Backend Development  >  Dynamic caching (S method) and fast caching (F method) in ThinkPHP

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

WBOY
WBOYOriginal
2016-07-29 09:13:06926browse

The default caching method of the system is File caching. We can define other caching methods in the project configuration file. For example, modify the default caching method to Xcache (of course, your environment needs to support Xcache)
For File caching There are a large number of file problems under the cache directory due to too much cached data. ThinkPHP also provides a solution, which can enable hash subdirectory caching.
'DATA_CACHE_SUBDIR'=>true

You can also set the level of the hash directory, for example

'DATA_PATH_LEVEL'=>2

You can automatically create multi-level subdirectories for caching based on the hash of the cache identifier.
Method S supports cache validity period. In many cases, we may not need the concept of validity period, or caching in file mode can meet the requirements, so the system also provides a fast caching method F method specifically for file mode. 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.
; '=>'3600',
//'DATA_CACHE_SUBDIR'=>true,//Open the subdirectory
//'DATA_CACHE_LEVEL'=>3,//Set the level of the subdirectory
Action file:
Function view( ) {缓 // Caches // $ cache = cache :: Getinstance ('cache method', 'cache parameter'); ;60));
                                                     // $cache->set('name', 'value'); or $cache->name='' name'); or $value=$cache->name;
                                                                                                                                                                                                                   . .
              $list=$user->select();
                                                                                                                                                                     ​ ​​dump($list);
}else{
                   echo 'This is a cache file';

The above introduces the dynamic caching (S method) and fast caching (F method) in ThinkPHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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