- 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 cache as file
- ' Data_cache_time ' = ' 600 ',//cache period 600 seconds
- );
- ?>
Copy Code
The use of the thinkphp cache function is cached in thinkphp with the shortcut cache function s (), for example:
- This class is automatically generated by the system and is intended for testing purposes only
- Class Indexaction extends action{
- Public Function index () {
- If there is a cache, read the cached data
- If there is no cache, the data in the read database is placed in the cache
- $lists =s (' lists ');
- if (Emptyempty ($lists)) {
- $news =m (' News ');
- $lists = $news->select ();
- S (' lists ', $lists, 600);
- Echo ' This is the data directly read from the database ';
- }
- Dump ($list);
- ?>
Copy Code
Accessing the Http://127.0.0.1/Home/index.php/Index/index output directly reads the data from the database:
- Array (10) {
- [0] = = Array (12) {
- ["id"] + = string (1) "1"
- ["catid"] = + string (2) "13"
- ["title"] and string (4) "Thinkphp Caching Technology"
- ["Content"] and string (8) "Thinkphp Caching Technology"
- ["tags"] + + string (4) "Cache"
- ["thumb"] = + string (0) ""
- ["description"] = + string (7) "Thinkphp Caching Technology"
- ["inputtime"] = + string (10) "1348370202"
- ["posid"] = + string (1) "1"
- ["ord"] = + string (1) "2"
- ["hits"] = + string (1) "1"
- [Status] = + string (1) "1"
- }
Copy Code
Note that the first run will print out the information shown above, after refreshing the page, "This is directly read data from the database", that is, read the previously generated cache data.
|