Thinkphp cache Getting Started Tutorial

Source: Internet
Author: User
Thinkphp cache Getting Started Tutorial

  1. Return array (
  2. 'Db _ type' => 'mysql ',
  3. 'Db _ host' => '2017. 0.0.1 ',
  4. 'Db _ name' => 'w3note ',
  5. 'Db _ user' => 'root ',
  6. 'Db _ pwd' => '123 ',
  7. 'Db _ port' => '123 ',
  8. 'Db _ prefix' => 'w3 _',
  9. 'Data _ CACHE_TYPE '=> 'File', // sets the cache mode to file.
  10. 'Data _ CACHE_TIME '=> '000000', // The cache cycle is 600 seconds.
  11. );
  12. ?>

The Thinkphp cache function is used in thinkphp to cache the function S (). For example:

  1. // This class is automatically generated by the system for testing purposes only
  2. Class IndexAction extends Action {
  3. Public function index (){
  4. // If cache exists, the cached data is read.
  5. // If no cache is available, the data read from the database is put into the cache.
  6. $ Lists = S ('lists ');
  7. If (emptyempty ($ lists )){
  8. $ News = M ('news ');
  9. $ Lists = $ news-> select ();
  10. S ('lists', $ lists, 600 );
  11. Echo 'This is the data that is directly read from the database ';
  12. }
  13. Dump ($ list );
  14. ?>

Access http: // 127.0.0.1/Home/index. php/Index/index to directly read data from the database:

  1. Array (10 ){
  2. [0] => array (12 ){
  3. ["Id"] => string (1) "1"
  4. ["Catid"] => string (2) "13"
  5. ["Title"] => string (4) "thinkphp cache technology"
  6. ["Content"] => string (8) "thinkphp cache technology"
  7. ["Tags"] => string (4) "cache"
  8. ["Thumb"] => string (0 )""
  9. ["Description"] => string (7) "thinkphp cache technology"
  10. ["Inputtime"] => string (10) "1348370202"
  11. ["Posid"] => string (1) "1"
  12. ["Ord"] => string (1) "2"
  13. ["Hits"] => string (1) "1"
  14. ["Status"] => string (1) "1"
  15. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.