当我运行时:
IpPermission.blacklist.pluck(:ip)
我得到结果:
=> ["127.0.0.11012q", "50.36.46.48"]
如果我手动更改 ip_permissions 表中的任何行,然后IpPermission.blacklist.pluck(:ip)
再次运行。它显示更新的结果。它不应该从缓存而不是直接从数据库加载结果吗?
我的模型看起来像:
class IpPermission < ActiveRecord::Base
validates_presence_of :ip, :note, :category
validates_uniqueness_of :ip, :scope => [:category]
validates :category, :inclusion => { :in => ['whitelist', 'blacklist'] }
def self.whitelist
Rails.cache.fetch('whitelist', :expires_in => 1.month) { self.where(:category => 'whitelist') }
end
def self.blacklist
Rails.cache.fetch('blacklist', :expires_in => 1.month) { self.where(:category => 'blacklist') }
end
end