module RailsEasyCaching

Constants

VERSION

Public Class Methods

config() { |configuration| ... } click to toggle source
# File lib/rails_easy_caching.rb, line 52
def config
  yield(configuration)
end
configuration() click to toggle source
# File lib/rails_easy_caching.rb, line 56
def configuration
  @@configuration ||= Configuration.new
end

Public Instance Methods

cache_data(key, attrs = nil) click to toggle source
# File lib/rails_easy_caching.rb, line 37
def cache_data(key, attrs = nil)
  records = reload.send(key)
  records = records.to_a if records.is_a?(ActiveRecord::Relation)

  if attrs.nil?
    records
  else
    records.map do |record|
      hash_data = Hash[attrs.map {|att| [att, record.send(att)]}]
      OpenStruct.new(hash_data)
    end
  end
end
cache_key(key) click to toggle source
# File lib/rails_easy_caching.rb, line 33
def cache_key(key)
  "#{self.class.to_s.downcase}_#{id}_#{key}"
end