各路神仙请显灵,该如何实现:可以缓存@ placements 里的数据,同时 placements 表中数据是会变化的,可否设置缓存时间,缓存失效后,重新查询 placements 表。
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "mysql2", :host => "10.1.1.130", :username => "xmo_prd", :database => "xmo", :encoding => "utf8", :password => "MWc200bs",)
class Plecement < ActiveRecord::Base
@placements =ActiveRecord::Base.connection.execute("select id, placement_name from placements").collect { |e| [e[0], e[1]] }
def self.tv_source(uid,placement_id)
return "" if (placement_id.nil? && uid.nil?)
uid.empty? ? @placements.detect { |e| placement_id == e[0]}[1].split("_")[0] : uid.split("_")[0]
end
end