Thinkphp cache Getting Started Tutorial
- Return array (
- 'Db _ type' => 'mysql ',
- 'Db _ host' => '2017. 0.0.1 ',
- 'Db _ name' => 'w3note ',
- 'Db _ user' => 'root ',
- 'Db _ pwd' => '123 ',
- 'Db _ port' => '123 ',
- 'Db _ prefix' => 'w3 _',
- 'Data _ CACHE_TYPE '=> 'File', // sets the cache mode to file.
- 'Data _ CACHE_TIME '=> '000000', // The cache cycle is 600 seconds.
- );
- ?>
The Thinkphp cache function is used in thinkphp to cache the function S (). For example:
- // This class is automatically generated by the system for testing purposes only
- Class IndexAction extends Action {
- Public function index (){
- // If cache exists, the cached data is read.
- // If no cache is available, the data read from the database is put into the cache.
- $ Lists = S ('lists ');
- If (emptyempty ($ lists )){
- $ News = M ('news ');
- $ Lists = $ news-> select ();
- S ('lists', $ lists, 600 );
- Echo 'This is the data that is directly read from the database ';
- }
- Dump ($ list );
- ?>
Access http: // 127.0.0.1/Home/index. php/Index/index to directly read data from the database:
- Array (10 ){
- [0] => array (12 ){
- ["Id"] => string (1) "1"
- ["Catid"] => string (2) "13"
- ["Title"] => string (4) "thinkphp cache technology"
- ["Content"] => string (8) "thinkphp cache technology"
- ["Tags"] => string (4) "cache"
- ["Thumb"] => string (0 )""
- ["Description"] => string (7) "thinkphp cache technology"
- ["Inputtime"] => string (10) "1348370202"
- ["Posid"] => string (1) "1"
- ["Ord"] => string (1) "2"
- ["Hits"] => string (1) "1"
- ["Status"] => string (1) "1"
- }
Note: During the first running, the information shown in the preceding figure is printed. after refreshing the page, "This is the data that is directly read from the database" is missing, that is, the previously generated cache data is read. |