Memcache客户端的使用方法
初始化的时候config/environment.rb
require 'memcache'
memcache_options = {
:compression => false,
:debug => false,
:namespace => "app-#{RAILS_ENV}",
:readonly => false,
:urlencode => false
}
memcache_servers = [ '127.0.0.1:4130' ]
cache_params = *(.flatten)
CACHE = MemCache.new *cache_params
使用的时候
Class TestController < ApplicationController
def index
value=CACHE.get(“testkey”)
if value!=nil
render :text=>"<h1>成功 : ”+value+”</h1>"
else
render :text=>”<h1>失敗</h1>”
end
end
end
以下转自Corey:ruby中星号(*)的作用(http://wuhuizhong.iteye.com/blog/219540)
4.创建数组
Ruby代码
*a = 1,3,"as"
a =
*a = 1,3,"as"
a =
5.数组参数传入时的前缀eg:
Ruby代码
a=
testFun(*a) == testFun(1 , 2) != testFun()
a=
testFun(*a) == testFun(1 , 2) != testFun()
页:
[1]