thinkphp Cache Getting Started tutorial

Source: Internet
Author: User
    1. Return Array (
    2. ' Db_type ' = ' mysql ',
    3. ' Db_host ' = ' 127.0.0.1 ',
    4. ' Db_name ' = ' w3note ',
    5. ' Db_user ' = ' root ',
    6. ' Db_pwd ' = ' 123456 ',
    7. ' Db_port ' = ' 3306 ',
    8. ' Db_prefix ' = ' w3_ ',
    9. ' Data_cache_type ' = ' file ',//set cache as file
    10. ' Data_cache_time ' = ' 600 ',//cache period 600 seconds
    11. );
    12. ?>
Copy Code

The use of the thinkphp cache function is cached in thinkphp with the shortcut cache function s (), for example:

    1. This class is automatically generated by the system and is intended for testing purposes only
    2. Class Indexaction extends action{
    3. Public Function index () {
    4. If there is a cache, read the cached data
    5. If there is no cache, the data in the read database is placed in 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 directly read from the database ';
    12. }
    13. Dump ($list);
    14. ?>
Copy Code

Accessing the Http://127.0.0.1/Home/index.php/Index/index output directly reads the data from the database:

    1. Array (10) {
    2. [0] = = Array (12) {
    3. ["id"] + = string (1) "1"
    4. ["catid"] = + string (2) "13"
    5. ["title"] and string (4) "Thinkphp Caching Technology"
    6. ["Content"] and string (8) "Thinkphp Caching Technology"
    7. ["tags"] + + string (4) "Cache"
    8. ["thumb"] = + string (0) ""
    9. ["description"] = + string (7) "Thinkphp Caching 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. }
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.

  • 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.