-
- return array(
- 'DB_TYPE'=>'mysql',
- 'DB_HOST'=>'127.0.0.1',
- 'DB_NAME'=>'w3note',
- ' DB_USER'=>'root',
- 'DB_PWD'=>'123456',
- 'DB_PORT'=>'3306',
- 'DB_PREFIX'=>'w3_',
- 'DATA_CACHE_TYPE'=>' file',//Set the cache mode to file
- 'DATA_CACHE_TIME'=>'600',//The cache period is 600 seconds
- );
- ?>
Copy code
Usage of Thinkphp cache function
Use the shortcut cache function S() in thinkphp for caching, for example:
-
- //This class is automatically generated by the system and is for testing purposes only
- class IndexAction extends Action{
- public function index(){
- //If there is a cache, read the cache data
- //If there is no cache, read the data from the database and put it into the cache
- $lists=S('lists');
- if(emptyempty($lists)){
- $news=M('news');
- $ lists=$news->select();
- S('lists',$lists,600);
- echo 'This is data directly read from the database';
- }
- dump($list);
- ?>
Copy the code
Visit http://127.0.0.1/Home/index.php/Index/index Output
Read data from the database directly:
-
- array(10) {
- [0] => array(12) {
- ["id"] => string(1) "1"
- ["catid"] => string( 2) "13"
- ["title"] => string(4) "thinkphp's caching technology"
- ["content"] => string(8) "thinkphp's caching technology"
- ["tags"] = > string(4) "caching"
- ["thumb"] => string(0) ""
- ["description"] => string(7) "thinkphp's caching technology"
- ["inputtime"] = > string(10) "1348370202"
- ["posid"] => string(1) "1"
- ["ord"] => string(1) "2"
- ["hits"] => string(1) "1"
- ["status"] => string(1) "1"
- }
Copy the code
Note that when running for the first time, the information shown above will be printed, After refreshing the page, there is no "This is data directly read from the database", that is, the previously generated cached data is read.
|