dalli

Cacheing an ActiveRecord Object that has_many through:

自作多情 提交于 2019-12-24 21:50:14
问题 When I try to cache an ActiveRecord object that has a has_many through: relationship, I can't cache the object until I reload or save it. person.rb: class Person < ActiveRecord::Base attr_accessible :name has_many :person_locations has_many :locations, through: :person_locations has_many :person_items has_many :items, through: :person_items end person_item.rb: class PersonItem < ActiveRecord::Base attr_accessible :item_id, :person_id belongs_to :item belongs_to :person end item.rb: class Item

How can I implement fragment cache with dalli when using pagination (kaminari)?

无人久伴 提交于 2019-12-24 13:53:00
问题 I know dalli (caching) is pretty powerful plugin to enhance performance for static pages. But what about dynamic pages with pagination, which are updated quite often? What is the correct way to set up dalli ? One problem I've encountered for example: dalli recognizes different params[:page] as the same page when using pagination:( How would you guys design the system when using dalli for both the page that gets updated so often the page that won't be updated so often For example. I have 4

How to increase memcache slab size above 1MB with dalli and Rails?

佐手、 提交于 2019-12-23 20:28:25
问题 I'm using Ruby on Rails and dalli gem to do caching with memcache. The default value (value as in key-value store, aka slab) max size is 1MB. I would like to increase this to 2MB. The documentation of dalli says: value_max_bytes: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here. With the -I option of memcached , how do I specify 2MB? Is it -I2 or -I2000? (the

Rails Cache Key generated as ActiveRecord::Relation

妖精的绣舞 提交于 2019-12-23 13:08:48
问题 I am attempting to generate a fragment cache (using a Dalli/Memcached store) however the key is being generated with "#" as part of the key, so Rails doesn't seem to be recognizing that there is a cache value and is hitting the database. My cache key in the view looks like this: cache([@jobs, "index"]) do The controller has: @jobs = @current_tenant.active_jobs With the actual Active Record query like this: def active_jobs self.jobs.where("published = ? and expiration_date >= ?", true, Date

Rails + Dalli memcache gem: DalliError: No server available

六眼飞鱼酱① 提交于 2019-12-21 03:19:20
问题 Hi I'm having trouble setting up my Rails project on my server because apache keeps complaining DalliError: No server available . I installed memcached on my ubuntu machine, but it still doesn't work. My rails project also has config.cache_store = :dalli_store, 'localhost:11211', { :namespace => "production" } in environments/production.rb. How would I debug this? My log shows before each request: localhost:11211 failed (count: 6) DalliError: No server available telnet to 11211: root@s2:/usr

How to specify memcache server to Rack::Session::Memcache?

主宰稳场 提交于 2019-12-13 16:32:22
问题 I'm trying to configure my Rack app to use Memcache for sessions with Rack::Session::Memcache How do I give it the options (such as server, username and password)? Presently I have use Rack::Session::Memcache But I get the error in `initialize': No memcache servers (RuntimeError) Heroku has put the config in environment variables MEMCACHE_PASSWORD: MEMCACHE_SERVERS: MEMCACHE_USERNAME: I know I can get these in Ruby with ENV['MEMCACHE_PASSWORD'] but I don't know how to give them to Rack:

Dalli: You are trying to cache a Ruby object which cannot be serialized to memcached

感情迁移 提交于 2019-12-13 04:35:51
问题 I'm getting weird behavior when I try to save an object in memory to the database and then cache that object with Dalli. class Infraction << ActiveRecord::Base has_many :infraction_locations has_many :tracked_points, through: :infraction_locations end class TrackedPoint << ActiveRecord::Base has_many :infraction_locations has_many :infractions, through: :infraction_locations end class InfractionLocation << ActiveRecord::Base belongs_to :infraction belongs_to :tracked_point belongs_to :rule

How to update expiration time in MemCached using Dalli?

空扰寡人 提交于 2019-12-13 01:54:18
问题 I'm using Ruby on Rails (v3.2.13), Dalli (v2.6.4) and MemCached (v1.4.13). I do caching like this: result = Rails.cache.fetch("test_key", :expires_in => 1.week) do get_data() # slow call, result of which should be cached end I want to update cache expiration date based on the data, since some of my data can be kept longer. Right now the following code does the job: if keep_longer(result) Rails.cache.write("test_key", result, :expires_in => 6.months) end I know that MemCached supports "touch"

How should I set up dalli for a dynamic page with lots of content updates?

百般思念 提交于 2019-12-13 01:18:37
问题 I know dalli (caching) is pretty useful to enhance performance for static sites. But what about dynamic sites, which are updated quite often? What is the correct way to set up dalli ? One problem I've encountered for example: dalli recognizes different params[:page] as the same page when using pagination:( How would you guys design the system when using dalli for both the page that gets updated so often the page that won't be updated so often My current code is just like this. That's why I'm

rails memcached dalli Marshalling error for key

心不动则不痛 提交于 2019-12-11 04:31:45
问题 I have such action in my controller: def my @user = Ads::User.find current_user.id @postings = Rails.cache.fetch("@user.postings.includes(:category)") do @postings = @user.postings.includes(:category) end end I'm trying to cache @postings and get such error: Marshalling error for key '@user.postings.includes(:category)': can't dump anonymous class #<Module:0x000000048f9040> You are trying to cache a Ruby object which cannot be serialized to memcached. If I try to cache @postings without