thinkphp 緩衝入門教程

來源:互聯網
上載者: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',//設定緩衝方式為file
  10. 'DATA_CACHE_TIME'=>'600',//緩衝周期600秒
  11. );
  12. ?>
複製代碼

Thinkphp緩衝函數的使用在thinkphp中用快捷緩衝函數S()進行緩衝,例如:

  1. // 本類由系統自動產生,僅供測試用途
  2. class IndexAction extends Action{
  3. public function index(){
  4. //如果有緩衝,則讀取快取資料
  5. //如果沒有緩衝,則讀取資料庫當中的資料放入緩衝
  6. $lists=S('lists');
  7. if(emptyempty($lists)){
  8. $news=M('news');
  9. $lists=$news->select();
  10. S('lists',$lists,600);
  11. echo '這是直接讀取資料庫的資料';
  12. }
  13. dump($list);
  14. ?>
複製代碼

訪問http://127.0.0.1/Home/index.php/Index/index 輸出直接讀取資料庫的資料:

  1. array(10) {
  2. [0] => array(12) {
  3. ["id"] => string(1) "1"
  4. ["catid"] => string(2) "13"
  5. ["title"] => string(4) "thinkphp的緩衝技術"
  6. ["content"] => string(8) "thinkphp的緩衝技術"
  7. ["tags"] => string(4) "緩衝"
  8. ["thumb"] => string(0) ""
  9. ["description"] => string(7) "thinkphp的緩衝技術"
  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. }
複製代碼

注意,第一次運行時,會列印出如上面所示資訊,重新整理一下頁面後,少了“ 這是直接讀取資料庫的資料",即讀取的是先前產生的快取資料。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.