Ruby system uses Memcache cache

Source: Internet
Author: User


http://guides.rubyonrails.org/

Take a closer look at the relevant parts of the cache in the manual, and note the following sentence:

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

The default development environment is not to open the cache, if we want to test the cache, we need to manually turn on, the default of false to True.


$vim config/environments/development.rb

Config.action_controller.perform_caching = True


The preparatory preparations have been finished and the formal start.

(1) first add the corresponding gem in the Gemfile, add the running $bundle install installation.



(2) in the corresponding interface folder to add the corresponding cache statement, from line 4th to line seventh, the middle deletion of the statement please ignore ~



(3) Increase the cache storage namespace in the CONFIG/APPLICATION.RB



(4) Add namespace to the config/settings.rb in the end.



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

(5) Check if there is a corresponding key generated

$ 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 [B; 1428992202 S]

END



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

Read the cache in log for the first request, and the second request reads only the cache without reading the table

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 = "an D pid_type = 1)

14:23:19 debug:sql (0.1ms) SELECT COUNT (*) from ' cms_client ' WHERE ' cms_client '. ' Pid_stat ' = 1 and ' cms_client '. ' Partn Er_mode ' = + (PID = ")

14:23:19 debug:sql (0.1ms) SELECT COUNT (*) from ' cms_client ' WHERE ' cms_client '. ' Pid_stat ' = 1 and ' cms_client '. ' Partn Er_mode ' = + and (PID = ")

14:23:19 debug:sql (0.1ms) SELECT COUNT (*) from ' cms_tv_pidlists ' WHERE ' cms_tv_pidlists '. ' state ' = 1 and (PID = "an D 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 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-OK in 42ms

14:24:18 INFO:


Hold CTRL +]

Telnet>

Enter quit to launch the


Ruby system uses Memcache cache

Related Article

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.