Module: ThreeD::ClassMethodCache::InstanceMethods

Defined in:
lib/three_d/class_method_cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_attribute!(att, value) ⇒ Object



166
167
168
169
170
171
# File 'lib/three_d/class_method_cache.rb', line 166

def cache_attribute!(att, value)
  m = self.method_cache.merge!(att.to_s => value)
  #self.personal_status.update_attributes(:method_cache => m)
  # => not using DB anymore
  return value
end

#cached?(att) ⇒ Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/three_d/class_method_cache.rb', line 158

def cached?(att)
  !self.method_cache[att.to_s].nil?  
end

#cached_attribute(att) ⇒ Object



162
163
164
# File 'lib/three_d/class_method_cache.rb', line 162

def cached_attribute(att)
  self.method_cache[att.to_s]
end

#clear_method_cache(meths = [], options = {}) ⇒ Object

Clear methods. Kann ein Methodenname, ein Array von Namen oder ein Regexp sein



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/three_d/class_method_cache.rb', line 175

def clear_method_cache(meths = [], options = {})
  if meths.is_a?(Regexp)   
    meths = self.method_cache.keys.select {|k| !k.match(meths).nil? }
  elsif meths.is_a?(Symbol) || meths.is_a?(String)
    meths = self.class.cached_methods[meths.to_sym]  
  elsif !meths.is_a?(Array)
    meths = meths.to_a
  end  

  begin 
    c = self.method_cache
    meths_all = c.keys
    meths_valid = []
    meths.each do |m|
      meths_all.each do |mv|
        meths_valid << mv if mv.match(m)
      end  
    end  
    CachingLog.info meths_valid.inspect
    meths_valid.each do |m|
      CachingLog.info "DELETE cache data: #{m}"
      CachingLog.info  "   for #{self.personal_data.first_name} #{self.personal_data.last_name}"
      c.delete(m)
    end
  rescue
    # wenn was schief läuft: $user_method_caching für den user auf {} setzen
    CachingLog.info "RESET CACHE (forced): #{self.full_name} / #{self.id}"
    self.class.cache_storage[self.id] = {}
  end  
end

#method_cacheObject



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/three_d/class_method_cache.rb', line 141

def method_cache
  m = self.class.cache_storage[self.id]
  if m.nil?
    # Wenn neue nutzer angelegt werden
    CachingLog.info "Create cache for #{self.class.name}(#{self.id})"
    self.class.cache_storage.merge!(self.id => {})
    self.class.cache_storage[self.id]
    return {}
  else
    return m
  end    
end

#method_cache=(val) ⇒ Object



154
155
156
# File 'lib/three_d/class_method_cache.rb', line 154

def method_cache=(val)
  self.class.cache_storage.merge!(self.id => val)
end

#reset_cacheObject



206
207
208
# File 'lib/three_d/class_method_cache.rb', line 206

def reset_cache
  self.class.cache_storage[self.id] = {}
end