2

Dalli と Memcachier を使用して Heroku にキャッシュを実装しています。キャッシュ ヒットを取得すると、返された配列 (または別の例ではハッシュ) にシンボルが追加されます。このシンボル :@new_record は、私が返している結果と関係があるとは知らず、さまざまな種類のキャッシュ フェッチに挿入されます。この問題で SO/Google で他の人を見つけることができませんでした。 . コードベース全体の検索では、「new_record」の結果が返されません。

この追加は、キャッシュを追加しようとした 2 つの場所で発生しました。そもそもそれが起こらないようにする方法はわかりませんが、返されたセットの各レコードのクラスをチェックし、サプライヤーでない場合はサプライヤーのプロファイルをレンダリングしないことで、この特定の用途での影響を回避します。これは醜い解決策であり、ソースで問題を解決したいと思います。

他にご不明な点がございましたら、お気軽にお問い合わせください。また、詳しい情報を投稿していただく必要があります。ご協力いただきありがとうございます。


私がキャッシングを使用している方法:

  #this will be slow, need to store it somewhere
  def self.set_for_index(index_name)
    guide = INDEX_HOLDER[index_name]
    return false if guide.nil?
    haves, have_nots, countries = guide[0], guide[1], guide[2]
    holder = []
    supplier_set = Rails.cache.fetch("set_for_index_#{index_name}", :expires_in => 24.hours) {
      Supplier.find_each do |s|
        if (
            s.profile_visible and
            (countries == [] or (s.address and countries.include?(s.address.country))) and
            !(haves.map{ |h| s.has_tag?(Tag.find_by_name(h).id) }.include?(false)) and
            !(have_nots.map{ |h| s.has_tag?(Tag.find_by_name(h).id) }.include?(true))
          )
            holder << s
        end
      end
      holder
    }
    return supplier_set
  end

このコードの最後の行を使用して、現在 :@new_record を選別しています。

def self.visible_profiles_sorted(index_name)
      profiles = Supplier.set_for_index(index_name)

      answer = {}

      if !(profiles.nil? or profiles == [])
        profiles.each do |s|  
          #block odd error where cache appends a :@new_record after the last result
          next if !s.is_a?(Supplier) or s.address.nil? or s.address.country.nil?
...

@new_record を除外しない場合のエラー [これは、上記のコードから行を削除したことによるものではなく、クラスベースのテストが実行できなかった場所でキャッシュを使用しようとした別の場所によるものです]:

2013-08-28T20:50:00.446550+00:00 heroku[web.1]: State changed from starting to up
2013-08-28T20:50:06.774001+00:00 app[web.1]: Dalli/SASL authenticating as af5c2c
2013-08-28T20:50:06.777925+00:00 app[web.1]: Dalli/SASL: af5c2c
2013-08-28T20:50:06.807129+00:00 app[web.1]: Started GET "/suppliers" for 70.36.146.74 at 2013-08-28 20:50:06 +0000
2013-08-28T20:50:10.671553+00:00 app[web.1]: 
2013-08-28T20:50:10.671553+00:00 app[web.1]:     37:                                    <td>
2013-08-28T20:50:10.671553+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for :@new_record:Symbol):
2013-08-28T20:50:10.671553+00:00 app[web.1]:     39:                                            <%= link_to s.name, supplier_profile_path(s.name_for_link) %>
2013-08-28T20:50:10.671553+00:00 app[web.1]:     40:                                            <%= image_tag 

application.rb の関連ビット:

module Partreach
  class Application < Rails::Application

    config.cache_store = :dalli_store

production.rb の関連ビット:

Partreach::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

Gemfile の関連ビット:

gem 'dalli', '2.6.4' #https://devcenter.heroku.com/articles/building-a-rails-3-application-with-memcache
gem 'memcachier', '0.0.2' #https://devcenter.heroku.com/articles/building-a-rails-3-application-with-memcache
4

1 に答える 1