Method: Cachy.key

Defined in:
lib/cachy.rb

.key(*args) ⇒ Object

Constructs a cache-key (first argument must be a String/Symbol)

Cachy.key :my_key Cachy.key :my_key, User.first, :locale=>:de Cachy.key :my_key, User.first, :without_locale=>true, :hash_key=>true



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cachy.rb', line 33

def self.key(*args)
  options = extract_options!(args)
  ensure_valid_keys options

  key = (args + meta_key_parts(args.first, options)).compact.map do |part|
    if part.respond_to? :cache_key
      part.cache_key
    else
      part
    end
  end * "_"

  key = (options[:hash_key] || hash_keys) ? hash(key) : key
  options[:prefix].to_s + key + options[:suffix].to_s
end