Sinatraã®ããã©ã¼ãã³ã¹ã¢ããä½æ¦
èªãµã¼ãã¹ãç¶ã
ã¨Sinatraã£ã¦ã¾ãã
ãã®éãããã©ã¼ãã³ã¹ã¢ãããçããMemcached(+memcache-client)ãå©ç¨ãããRailsã®ãã©ã°ã¡ã³ããã£ãã·ã¥ã©ã¤ã¯ã«ä½¿ããExtensionãæ¸ãã¾ããã
使ãæ¹ãã³ã¼ãã¯ã³ãã©ã«ããã¾ã
http://github.com/gioext/sinatra-memcache/tree/master
使ãæ¹
# start memcached cd myapp git clone git://github.com/gioext/sinatra-memcache.git lib/sinatra-memcache
# app.rb require 'rubygems' require 'sinatra' require File.dirname(__FILE__) + '/lib/sinatra-memcache/lib/sinatra/memcache' # ãã¼ã¸ãã£ãã·ã¥ã®ããã«ä½¿ã£ãã get '/cache1' do cache 'cache1' do sleep(5) 'Hello Cache1' end end # å¼æ°ã§æå¹æéãå§ç¸®ã®è¨å®ããã get '/cache2' do cache 'cache2', :expiry => 10, :compress => true do sleep(3) 'Hello Cache2' end end # ãªãã¸ã§ã¯ãããã£ãã·ã¥ããã get '/obj' do hash = cache 'obj' do sleep(2) { :a => 'Hello Object' } end hash[:a] end # ãã¼ãæ£è¦è¡¨ç¾ã§ãã£ãã·ã¥ãæ¶ããã get '/expire' do expire 'cache1' expire /^cache/ expire // 'Hello Expire' end # ããã©ã«ãã®ãªãã·ã§ã³ # éçºæã¯ãã£ãã·ã¥ç¡å¹ãå # configure :development do # set :cache_enable, false # end configure do set :cache_server, 'localhost:11211' set :cache_namespace, 'sinatra-memcache' set :cache_enable, true set :cache_logging, true end
試ãã¦ãªãã§ããMemCacheäºæã®APIãæã¤TokyoTyrantçã§ãåãã¨ä¿¡ãã¦ã¾ã
ããã¾ã