Module: Kaching

Defined in:
lib/kaching.rb,
lib/kaching/railtie.rb,
lib/kaching/version.rb,
lib/kaching/cache_list.rb,
lib/kaching/cache_counter.rb,
lib/kaching/model_additions.rb,
lib/kaching/cache_counter_onmethod.rb,
lib/kaching/storage_providers/redis.rb,
lib/kaching/storage_providers/memory.rb

Defined Under Namespace

Modules: CacheCounter, CacheList, ModelAdditions, StorageProviders Classes: Railtie

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

._extract_foreign_key_from(attribute, options, container_class) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kaching/model_additions.rb', line 22

def self._extract_foreign_key_from(attribute, options, container_class)
  foreign_key = options[:foreign_key]
          
  if !foreign_key
    reflection = container_class.reflections[attribute]
    foreign_key = reflection.options[:foreign_key] if reflection
  end

  foreign_key = if foreign_key
    foreign_key.gsub(/_id$/, "")
  else
    container_class.name.underscore.singularize
  end
  
  foreign_key
end

.cache_storeObject

def self.attributes

@attributes ||= []

end



10
11
12
# File 'lib/kaching/model_additions.rb', line 10

def self.cache_store
  Kaching::StorageProviders.Redis
end

.loggerObject



14
15
16
17
18
19
20
# File 'lib/kaching/model_additions.rb', line 14

def self.logger
  @logger ||= begin
    logger = Logger.new(ENV['ATTRIBUTE_CACHE_LOG'] ? $stdout : '/dev/null')
    logger.level = Logger::INFO
    logger
  end
end