# :mem\_cache\_store and memcache-client

**URL:** <https://www.ruby-forum.com/t/mem-cache-store-and-memcache-client/109125>\
**Category:** Rails\
**Created:** [July 11, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/mem-cache-store-and-memcache-client/109125 "2007-07-11T17:24:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [July 11, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/mem-cache-store-and-memcache-client/109125/1 "2007-07-11T17:24:35Z")

</div>

Seems to not be working in that there is no error, but my Rails app is  
not keeping track of any session. Fragment cache is working, however. I  
have tried many different ways, but just can’t get this to work. My  
memcached-vv also looks normal. Can someone please help me, or tell me  
where to start looking.

evironment.rb:

require File.join(File.dirname( **FILE** ), ‘boot’)  
require\_gem ‘memcache-client’

memcache\_options = {  
:compression =\> false,  
:debug =\> false,  
:namespace =\> ‘domain’,  
:readonly =\> false,  
:urlencode =\> false  
}  
memcache\_servers = “localhost:11211”

Rails::Initializer.run do |config|  
config.action\_controller.session\_store = :mem\_cache\_store  
config.action\_controller.fragment\_cache\_store = :mem\_cache\_store,  
memcache\_servers, memcache\_options  
#config.action\_controller.fragment\_cache\_store = CACHE, {}  
#ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.merge!({  
‘cache’ =\> CACHE })

require ‘hodel\_3000\_compliant\_logger’  
config.logger = Hodel3000CompliantLogger.new(config.log\_path)  
end

cache\_params = \*([memcache\_servers, memcache\_options].flatten)  
CACHE = MemCache.new \*cache\_params  
ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.merge!({ ‘cache’  
=\> CACHE })

ActionMailer::Base.delivery\_method = :smtp

ActionMailer::Base.server\_settings = {  
:address =\> “[mail.domain.com](http://mail.domain.com)”,  
:port =\> 25,  
:domain =\> “[domain.com](http://domain.com)”,  
}

ActionMailer::Base.perform\_deliveries = true  
ActionMailer::Base.raise\_delivery\_errors = true  
ActionMailer::Base.default\_charset = “utf-8”

require ‘RMagick’  
include Magick  
require ‘cgi’  
require ‘cached\_model’  
require ‘misc’

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [September 26, 2008, 8:06am UTC](https://www.ruby-forum.com/t/mem-cache-store-and-memcache-client/109125/2 "2008-09-26T08:06:16Z")

</div>

Hi,

Above code is working fine,

you assign the memcached server where you run memcache server

memcache\_servers = “localhost:11211”

above line you replace localhost as IP(i.e,)where memcache server  
running  
ex:memcache\_servers = “168.162.10.26:11211” – like this

and start memcache server using this cmd

memcached -d -m 256 -u nobody -p 11211 -l 168.162.10.26

any doubt in this mail me.

regrads,  
T.Sathish  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [April 21, 2009, 1:53am UTC](https://www.ruby-forum.com/t/mem-cache-store-and-memcache-client/109125/3 "2009-04-21T01:53:06Z")

</div>

It seems to be working except that I am getting key too long error. If  
possible, can you tell me what I am missing?

I will really appreciate your help.

Processing ApplicationController#index (for 74.203.51.2 at 2009-04-20  
23:38:54) [GET]

ActionView::TemplateError (key too long  
“rack:session:BAh7FzoQQWRkcmVzc0luZm8wOg9zZXNzaW9uX2lkIiVhNjQ2NDdhNDk2YmZjZjRhY2I2M2UyNTQ1ZTIzMDAwNToPY2FjaGVfZGF0YTA6F2Zvcm1fc3VibWl0X2Vycm9yczA6E2hvdGVsX2dlb19kYXRhex4iCzIwNjAwNXsHOg1sYXRpdHVkZSINNDcuNjIyNDQ6DmxvbmdpdHVkZSIPLTEyMi4zNTY3MiILMTg2MjQxewc7CiINNDcuNjI5NTQ7CyIPLTEy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yIgsxMzIxMzh7BzsKIg00Ny42MDY4MjsLIg8tMTIyLjMzMzU4OhJsb2NhdGlvbl9pbmZvMDoSc2VhcmNoX2VuZ2luZTA6EWd1ZXN0X2NvdW50c3sHOg9udW1fYWR1bHRzIgYyOhFudW1fY2hpbGRyZW4iBjA6F2hvdGVsX2Jvb2tpbmdfaW5mbzA6EGZvcm1fcGFyYW1zMDoXZ3Vlc3RfY2xpY2tzX2NvdW50aRo6DXJvb21feG1sIgGGPFJvb21Hcm91cD48Um9vbT48bnVtYmVyT2ZBZHVsdHM+MjwvbnVtYmVyT2ZBZHVsdHM+CjxudW1iZXJPZkNoaWxkcmVuPjA8L251bWJlck9mQ2hpbGRyZW4+CjxjaGlsZEFnZXM+PC9jaGlsZEFnZXM+CjwvUm9vbT48L1Jvb21Hcm91cD46DWxhc3RQYWdlIgYvOhBsYXlvdXRfZmlsZSINYXV0b3Rvb2w6FFJlc2VydmF0aW9uSW5mbzA6GWhvdGVsX2RlcGFydHVyZV9kYXRlIg8wNy8yNy8yMDA5IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOhdob3RlbF9hcnJpdmFsX2RhdGUiDzA3LzI1LzIwMDk=–44dde50c649bf5bb1e8e3688fd16e884024ee78d”)  
on line #40 of app/views/shared/\_header.rhtml:  
37: if(typeof(onloadJSDelegate)==‘function’){  
38: onloadJSDelegate();  
39: }  
40: \<%if(!flash[:notice].blank?)%\>  
41: alert(’\<%=flash[:notice]%\>’)  
42: \<%end%\>  
43: }

My config/environment.rb looks like this -  
require ‘memcache’  
memcache\_options = {  
:compression =\> true,  
:debug =\> false,  
:namespace =\> ‘outlook’,  
:readonly =\> false,  
:urlencode =\> false  
}

memcache\_servers = ‘[IP Address]:11211’

Rails::Initializer.run do |config|

# Settings in config/environments/\* take precedence over those

specified here

# Add additional load paths for your own custom dirs

# config.load\_paths += %W( #{RAILS\_ROOT}/extras )

config.load\_paths += %W(  
#{RAILS\_ROOT}/lib  
)

# Use the database for sessions instead of the file system

# (create the session table with ‘rake db:sessions:create’)

# config.action\_controller.session\_store = :active\_record\_store

#config.action\_controller.fragment\_cache\_store = :mem\_cache\_store,  
memcache\_servers, memcache\_options

config.action\_controller.session = {  
:session\_key =\> ‘\_tripoutlook\_session\_id’,  
:secret =\> ‘tripoutlook\_a1b2c3d4e5g6h7i8’  
}  
config.action\_controller.session\_store = :mem\_cache\_store

end

cache\_params = \*([memcache\_servers, memcache\_options].flatten)  
Cache = MemCache.new \*cache\_params
