ruby系統使用memcache緩衝

來源:互聯網
上載者:User

標籤:緩衝   caching   cache   ruby   rails   


      http://guides.rubyonrails.org/

     仔細讀一下手冊裡的關於cache的相關部分,注意一句話:

 This flag is normally set in the corresponding config/environments/*.rb and caching is disabled by default for development and test, and enabled for production.

預設的開發環境是沒有開啟緩衝的,如果我們要測試緩衝,需要手動開啟,把預設的false改為true。


$vim config/environments/development.rb

config.action_controller.perform_caching = true


準備活動做完了正式開始啦。

(1)首先在Gemfile裡增加對應的gem,增加完運行 $bundle install 安裝一下。



(2)在對應的interface檔案夾裡新增相應的cache語句,從第4行到第七行,中間刪除的語句請忽略~



(3)在config/application.rb裡增加cache儲存的namespace



(4)最後要在config/settings.rb裡增加namespace



======================

(5)查一下是否有產生對應的key

$ telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is ‘^]‘.

stats

STAT pid 1024

STAT uptime 99957

STAT time 1428992525

STAT version 1.4.13

STAT libevent 2.0.16-stable

STAT pointer_size 64

STAT rusage_user 1.024064

STAT rusage_system 0.816051

STAT curr_connections 7

STAT total_connections 9

STAT connection_structures 8

STAT reserved_fds 20

STAT cmd_get 15

STAT cmd_set 2

STAT cmd_flush 0

STAT cmd_touch 0

STAT get_hits 0

STAT get_misses 15

STAT delete_misses 0

STAT delete_hits 0

STAT incr_misses 0

STAT incr_hits 0

STAT decr_misses 0

STAT decr_hits 0

STAT cas_misses 0

STAT cas_hits 0

STAT cas_badval 0

STAT touch_hits 0

STAT touch_misses 0

STAT auth_cmds 0

STAT auth_errors 0

STAT bytes_read 1720

STAT bytes_written 633

STAT limit_maxbytes 67108864

STAT accepting_conns 1

STAT listen_disabled_num 0

STAT threads 4

STAT conn_yields 0

STAT hash_power_level 16

STAT hash_bytes 524288

STAT hash_is_expanding 0

STAT expired_unfetched 0

STAT evicted_unfetched 0

STAT bytes 157

STAT curr_items 1

STAT total_items 2

STAT evictions 0

STAT reclaimed 0

END


ERROR


ERROR


ERROR

stats items

STAT items:4:number 1

STAT items:4:age 936

STAT items:4:evicted 0

STAT items:4:evicted_nonzero 0

STAT items:4:evicted_time 0

STAT items:4:outofmemory 0

STAT items:4:tailrepairs 0

STAT items:4:reclaimed 0

STAT items:4:expired_unfetched 0

STAT items:4:evicted_unfetched 0

END

stats cachedump 4 100

ITEM ott-youku-cms-development:views/ce5f4eac26ac2773a497d1d557255964.json [22 b; 1428992202 s]

END



===============

在log裡查看是第一次請求的時候寫cache,第二次請求唯讀取cache,不用讀表

Started GET "/interface/system_control/xx_blacklists.json" for 127.0.0.1 at 2015-04-14 14:23:19 +0800 

14:23:19 INFO:   Processing by Interface::SystemControlController#xx_blacklists as JSON 

14:23:19 DEBUG: Cache read: views/ce5f4eac26ac2773a497d1d557255964.json ({:expires_in=>600}) 

14:23:19 INFO: Read fragment views/ce5f4eac26ac2773a497d1d557255964.json (0.4ms) 

14:23:19 DEBUG:   SQL (0.1ms)  SELECT COUNT(*) FROM `cms_tv_pidlists` WHERE `cms_tv_pidlists`.`state` = 1 AND (pid = ‘‘ and pid_type = 1) 

14:23:19 DEBUG:   SQL (0.1ms)  SELECT COUNT(*) FROM `cms_client` WHERE `cms_client`.`pid_stat` = 1 AND `cms_client`.`partner_mode` = 12 AND (pid = ‘‘) 

14:23:19 DEBUG:   SQL (0.1ms)  SELECT COUNT(*) FROM `cms_client` WHERE `cms_client`.`pid_stat` = 1 AND `cms_client`.`partner_mode` = 17 AND (pid = ‘‘) 

14:23:19 DEBUG:   SQL (0.1ms)  SELECT COUNT(*) FROM `cms_tv_pidlists` WHERE `cms_tv_pidlists`.`state` = 1 AND (pid = ‘‘ and pid_type = 2) 

14:23:19 DEBUG:   SQL (0.1ms)  SELECT COUNT(*) FROM `cms_tv_blacklists` WHERE `cms_tv_blacklists`.`state` = 1 AND `cms_tv_blacklists`.`blacklist_type` = ‘UA‘ AND (code = ‘‘) 

14:23:19 DEBUG: Cache write: views/ce5f4eac26ac2773a497d1d557255964.json ({:expires_in=>600}) 

14:23:19 INFO: Write fragment views/ce5f4eac26ac2773a497d1d557255964.json (0.4ms) 

14:23:19 INFO: Completed 200 OK in 74ms (Views: 3.0ms | ActiveRecord: 0.5ms) 



14:24:18 INFO: 


Started GET "/interface/system_control/xx_blacklists.json" for 127.0.0.1 at 2015-04-14 14:24:18 +0800 

14:24:18 INFO:   Processing by Interface::SystemControlController#youku_blacklists as JSON 

14:24:18 DEBUG: Cache read: views/ce5f4eac26ac2773a497d1d557255964.json ({:expires_in=>600}) 

14:24:18 INFO: Read fragment views/ce5f4eac26ac2773a497d1d557255964.json (0.4ms) 

14:24:18 INFO: Completed 200 OK in 42ms 

14:24:18 INFO: 


按住 ctrl + ]

telnet> 

輸入quit 就可以推出了


ruby系統使用memcache緩衝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.