Sha256: d51072d8b24a1e7b726fa35973541fbc96481473156e9909f1beaba2177e7167

Contents?: true

Size: 661 Bytes

Versions: 1

Compression:

Stored size: 661 Bytes

Contents

module Highrise
  class Tag < Base    
    @cache = self.cache_store || ActiveSupport::Cache::MemoryStore.new
    
    def ==(object)
      (object.instance_of?(self.class) && object.id == self.id && object.name == self.name)
    end
    
    class << self
      # This find(:all) is very expensive, so cache all tags, once.
      def find_by_name(arg)
        @cache.fetch(to_key([self.to_s, arg])) {
          tags = self.find(:all).each{|tag| @cache.write(to_key([self.to_s, tag.name]), tag)}
          tags.find{|tag| tag.name == arg}
        }
      end
      
      private
      
      def to_key(*args)
        args.join('/')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
highrise-1.2.0 lib/highrise/tag.rb