Note that there are some explanatory texts on larger screens.

plurals
  1. POdalli session store
    primarykey
    data
    text
    <p>I have been googling for a long time and haven't find a solution yet. I am using Rails 3.2 and the Dalli gem with memcached 1.4.14.</p> <p>I would like to use Dalli/Memcached as the session store but I dont know how to do that. Now, Dalli cache works like a classic cache but not the session cache. I created a new rails app, added Dalli to the Gemfile :</p> <pre><code>gem 'dalli' </code></pre> <p>In development and production environments I set Dalli as the cache store:</p> <pre><code>config.cache_store = :dalli_store </code></pre> <p>This is the content of <code>initializers/session_store.rb</code>:</p> <pre><code>require 'action_dispatch/middleware/session/dalli_store' Rails.application.config.session_store :dalli_store, :memcache_server =&gt; ['127.0.0.1'], :namespace =&gt; 'sessions', :key =&gt; '_session', :expire_after =&gt; 30.minutes </code></pre> <p>I create a <code>Myooo</code> model in which I added to methods to list and create instances:</p> <pre><code>def self.index_c a = Rails.cache.read(:myooo_index) if a.nil? puts '---&gt;&gt;&gt; load again' a = Rails.cache.write(:myooo_index, Myooo.all, expires_in: 5.seconds) else puts '---&gt;&gt;&gt; using cache' end return Rails.cache.read(:myooo_index) end def self.create_c(myooo_object) a = Rails.cache.read(:myooo_create) if a.nil? a = Rails.cache.write(:myooo_create, myooo_object, expires_in: 10.minutes) end return Rails.cache.read(:myooo_create) end </code></pre> <p>In the controller, I just try to reach the cache. In the index action:</p> <pre><code>@myooos = Myooo.index_c </code></pre> <p>and in the create action:</p> <pre><code>@myooo = Myooo.new(params[:myooo]) Myooo.create_c(@myooo) </code></pre> <p>I know it's a strange script but i need to understand how I'm supposed to deal with the session cache and use it in a real project. I spent a lot of time in server outline console, made many puts trying to understand what's going on. Cache seems to act like a classic cache, not a session cache.</p> <p>I would be glad to be helped (ps: happy new year) :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload