Class: CamaleonRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveRecordExtras::Relation
Defined in:
app/models/camaleon_record.rb

Instance Method Summary collapse

Instance Method Details

#cama_build_cache_key(key) ⇒ Object

internal helper to generate cache key



43
44
45
# File 'app/models/camaleon_record.rb', line 43

def cama_build_cache_key(key)
  _key = "cama_cache_#{self.class.name}_#{id}_#{key}"
end

#cama_fetch_cache(key) ⇒ Object

fetch the cache value for this key



21
22
23
24
25
26
27
28
29
30
# File 'app/models/camaleon_record.rb', line 21

def cama_fetch_cache(key)
  @cama_cache_vars ||= {}
  _key = cama_build_cache_key(key)
  if @cama_cache_vars.key?(_key)
    # puts "*********** using model cache var: #{_key}"
  else
    @cama_cache_vars[_key] = yield
  end
  @cama_cache_vars[_key]
end

#cama_get_cache(key) ⇒ Object

return the cache value for this key



33
34
35
36
37
38
39
40
# File 'app/models/camaleon_record.rb', line 33

def cama_get_cache(key)
  @cama_cache_vars ||= {}
  begin
    @cama_cache_vars[cama_build_cache_key(key)]
  rescue StandardError
    nil
  end
end

#cama_remove_cache(key) ⇒ Object

remove cache value for this key



16
17
18
# File 'app/models/camaleon_record.rb', line 16

def cama_remove_cache(key)
  @cama_cache_vars.delete(cama_build_cache_key(key))
end

#cama_set_cache(key, val) ⇒ Object

save cache value for this key



9
10
11
12
13
# File 'app/models/camaleon_record.rb', line 9

def cama_set_cache(key, val)
  @cama_cache_vars ||= {}
  @cama_cache_vars[cama_build_cache_key(key)] = val
  val
end